在asp.net页面中输入下面提到的代码浏览器只显示消息但是如果我想添加我创建的按钮怎么样 - > OK和CANCEL以及OK按钮我必须编写一些代码:
if (isUpdateXMLReportDataSuccess == true)
{
Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");
Response.Redirect("./ManageDefects.aspx");
}
else
{Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug not created successfully." + "')</SCRIPT>"); return;}
另外在这里我想问一下,在我的情况下,如果isUpdateXMLReportDataSuccess
是true
,那么根据代码浏览器首先需要显示消息,即&#34; Bug已成功创建。&#34 ;然后它应该重新直接重定向(&#34; ./ ManageDefects.aspx&#34;);
但就我而言,它会转到Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");
,但不会在浏览器上显示该消息,而是直接转到Response.Redirect("./ManageDefects.aspx");
它没有显示浏览器消息。
答案 0 :(得分:2)
HTTP不起作用。
当您执行重定向 - Response.Redirect(path)
时 - 浏览器只会收到"go there" instruction,但不会显示任何网页内容,因此不会显示您的提醒。
如果要显示此类提醒,则必须在“此处”页面(在您的示例中为ManageDefects.aspx
)显示该提醒,或者不要执行重定向。
答案 1 :(得分:1)
Instead of
Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT>");
Response.Redirect("./ManageDefects.aspx");
Use this
ScriptManager.RegisterStartupScript(this, typeof(string), "redirect", "alert('message goes here'); window.location='" + Request.ApplicationPath + "/foldername/pagename.aspx';", true);
答案 2 :(得分:0)
if (isUpdateXMLReportDataSuccess == true)
{
//Here call ScriptManagar
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "Javascript:ShowDetails();", true);
}
// Javascript功能
ShowDetails()
{
$("#yOURdIV").show();
}
// HTML
<div id="yOURdIV" class="dialog_content pop-box" style="height: 95px; display: none; position: absolute; left: 30%; top: 65%;">
<div class="pop-head">
Select Reject Remarks
</div>
<div class="pop-content" style="margin-top: 5px;">
<asp:Button ID="btnoK" runat="server" Text="Confirm"/>
<asp:Button ID="btnCANCEL" runat="server" Text="Cancel" />
</div>
</div>
OnCLick just change `Div` Display to `Block`
And ON Click of OK and Cancel write your code //
现在响应重定向并提醒您可以采取两种方式
第一:
ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "alert('Request has been on submitted')", true);
string url = "abc.aspx";
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "Javascript:alertMesg('" + url + "');", true);
致电JS:
function alertMesg(url )
{
window.location.href = url;
win.focus();
}
第二道:
ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "alert('Your Alert Message'); window.location='" + Request.ApplicationPath + "/Abc.aspx';", true);