C# 如何显示浏览器消息和关于消息点击事件需要处理的代码?
在asp.net页面中,通过输入下面提到的代码浏览器仅显示消息,但如果要添加我创建的按钮,如-->确定和取消,以及在确定按钮上,我必须编写一些代码:C# 如何显示浏览器消息和关于消息点击事件需要处理的代码?,c#,asp.net,C#,Asp.net,在asp.net页面中,通过输入下面提到的代码浏览器仅显示消息,但如果要添加我创建的按钮,如-->确定和取消,以及在确定按钮上,我必须编写一些代码: if (isUpdateXMLReportDataSuccess == true) { Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('" + "Bug created successfully." + "')</SCRIPT&
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;}
if(isUpdateXMLReportDataSuccess==true)
{
响应。写入(@“警报(“+”错误已成功创建。“+”)”);
Response.Redirect(“./ManageDefects.aspx”);
}
其他的
{Response.Write(@“警报(“+”错误未成功创建。“+”)”)”;return;}
这里我还想问一下,在我的例子中,如果isUpdateXMLReportDataSuccess
是true
,那么根据代码浏览器,首先需要显示消息,即“Bug created successfully.”,然后它应该直接重新重定向(“./ManageDefects.aspx”)
但在我的例子中,它转到Response.Write(@“alert”(“+”错误创建成功。“+”))代码>但不在浏览器上显示消息,直接转到Response.Redirect(“./ManageDefects.aspx”)代码>
它没有显示浏览器消息
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 //
打电话给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);
//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 //
打电话给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);
不是那样的
当您执行重定向-响应。重定向(路径)
-浏览器只接收到没有任何页面内容的消息,因此不会显示您的警报
如果要显示此类警报,您必须在“there”页面中显示它(在您的示例中为ManageDefects.aspx
),或者不执行重定向。不能以这种方式工作
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);
当您执行重定向-响应。重定向(路径)
-浏览器只接收到没有任何页面内容的消息,因此不会显示您的警报
如果要显示此类警报,您必须在“there”页面中显示它(在您的示例中为ManageDefects.aspx
),或者不执行重定向。而不是
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);
响应。写入(@“警报(“+”错误已成功创建。“+”)”);
Response.Redirect(“./ManageDefects.aspx”);
用这个
ScriptManager.RegisterStartupScript(这个,typeof(string),“重定向”,“警报('消息在这里');window.location='“+Request.ApplicationPath+”/foldername/pagename.aspx';”,true);
而不是
响应。写入(@“警报(“+”错误已成功创建。“+”)”);
Response.Redirect(“./ManageDefects.aspx”);
用这个
ScriptManager.RegisterStartupScript(这个,typeof(string),“重定向”,“警报('消息在这里');window.location='“+Request.ApplicationPath+”/foldername/pagename.aspx';”,true);
Read the please:Write方法将指定字符串写入当前HTTP输出。Read the please:Write方法将指定字符串写入当前HTTP输出。如果您希望在重定向之前显示消息,请使用上述代码,如果您希望确定取消按钮,请仅使用确认(“消息到此!”);我也会这样做,而不是提醒(“消息”)。事实上,我是在写这样的东西。但是你更快了xDHi感谢我的案例上述解决方案有效。。竖起大拇指。感谢如果您希望在重定向之前显示消息,请使用上述代码,如果您希望确定取消按钮,请仅使用确认(“消息转到此处!”);我也会这样做,而不是提醒(“消息”)。事实上,我是在写这样的东西。但是你更快了xDHi感谢我的案例上述解决方案有效。。竖起大拇指。谢谢