来自aspx.cs页面的确认警报框 [英] confirmation alert box from aspx.cs page

查看:104
本文介绍了来自aspx.cs页面的确认警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望从aspx.cs页面获得一个JavaScript确认消息框.在某些按钮单击功能中,我想编写不在Page_Load中的代码.
在执行过程中需要确认框,以便如果用户单击确定",则应进一步处理,对于Cancle单击,应在服务器端出现,而无需执行其余代码.

请在需要此功能的地方找到代码

受保护的void cmdSolve_ServerClick(object sender,System.EventArgs e)
{
字符串名称= dtAttachedFiles.Rows [i] ["FileName"].ToString().ToUpper();
如果(name.Contains("BACKOUT"))
{
字符串ext = Path.GetExtension(name);
如果(ext!=".PDF")
{
Response.Write(< script language = Javascript> confirm((\\没有附加的回退计划.\");</script>);
}

//其余代码
}



在执行的这一点上,我希望弹出.单击确定"将执行其余代码,单击取消"将不执行其余代码...

解决方案

您可以使用类似以下内容的代码:

///<  摘要 <  请参见    cref   ="  / > .
///<  /summary  > 
///<   param    名称  ="  <  参见    cref   ="  > ./param  <   param    名称  ="  <  > 
公共静态无效ConfirmButton(WebControl控件,字符串Message)
{
    如果(Control!= null)
    {
        Control.Attributes.Add("onclick","javascript:if(confirm('" + Message +')== false)返回false;");
    }
} 



在页面的OnLoad事件中调用此函数,并传递控件名称(通常是按钮)和要显示的消息.如果用户选择取消",则不会发生任何事情.如果他们选择确定",则该过程将继续.

您应该能够使它适应您的特定需求:如果您不确定如何进行研究就可以解决这个问题.


好(而且很简单)创建警报框的示例此处 [ if (name.Contains("BACKOUT"))
{
string ext = Path.GetExtension(name);
if (ext != ".PDF")
{
Response.Write(<script language=Javascript>confirm((\"There is no Backout Plan attached.\");</script>);
}

//Rest of the code
}



in this point of execution i want that pop up. On OK click it will execute the rest of the code and Cancel click it will not execute the rest of the code...

解决方案

You can use something like the following:

/// <summary>
/// Add a javascript confirm to a <see cref="WebControl"/>.
/// </summary>
/// <param name="control">Would normally expect this to be a <see cref="Button"/>.</param>
/// <param name="Message">The message to display.</param>
public static void ConfirmButton(WebControl Control, string Message)
{
    if (Control != null)
    {
        Control.Attributes.Add("onclick", "javascript:if(confirm('" + Message + "') == false) return false;");
    }
}



Call this in the OnLoad event of the page passing the name of the control (usually a button) and a message to display. If the user chooses ''Cancel'' nothing will happen. If they choose ''Ok'' the process will continue.

You should be able to adapt this to your specific needs: if you''re not sure how you''ll need to do some research to figure it out.


Good (and simple) example to create an alert box here[^].


这篇关于来自aspx.cs页面的确认警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆