Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Updatepanel内的MessageBox不显示_C#_Asp.net_Updatepanel - Fatal编程技术网

C# Updatepanel内的MessageBox不显示

C# Updatepanel内的MessageBox不显示,c#,asp.net,updatepanel,C#,Asp.net,Updatepanel,我使用的c#中的Messagebox代码是以下代码,它是根据我的需求有条件地调用的。除了使用Ajax更新面板外,它在所有情况下都可以正常工作。 例如,如果在gridview中没有选中复选框,我想用 适当的消息,执行代码,但不显示消息框 public static void MessageBox(string message, Page page) { if (!string.IsNullOrEmpty(message)) {

我使用的c#中的Messagebox代码是以下代码,它是根据我的需求有条件地调用的。除了使用Ajax更新面板外,它在所有情况下都可以正常工作。 例如,如果在gridview中没有选中复选框,我想用 适当的消息,执行代码,但不显示消息框

 public static void MessageBox(string message, Page page)
    {       
        if (!string.IsNullOrEmpty(message))
        {
            Label lbl = new Label();
            lbl.Text = "<script type=\"text/javascript\" language=\"javascript\">" + "alert('" + message + "'); " + "</script>";
            page.Controls.Add(lbl);
        }
    }
公共静态无效消息框(字符串消息,第页)
{       
如果(!string.IsNullOrEmpty(消息))
{
标签lbl=新标签();
lbl.Text=“+”警报(“+”消息+”);“+”;
页面控件添加(lbl);
}
}

看起来您正在将标签直接添加到页面上。这对于完整回发场景(您提到过它)来说很好,但是如果您不直接将其添加到UpdatePanel中的某个位置,它将不会写入部分回发的页面。

看起来您是在将标签直接添加到页面上。这对于完整的回发场景(您提到过它)很好,但是如果您不直接在UpdatePanel中添加它,它不会写入部分回发上的页面。

使用ScriptManager.RegisterClientScriptBlock或ClientScriptManager.RegisterClientScriptBlock方法在使用更新面板时添加脚本


这方面的一个示例是

使用ScriptManager.RegisterClientScriptBlockClientScriptManager.RegisterClientScriptBlock方法在使用更新面板时添加脚本


据我所知,UpdatePanel中的Ajax回发仅使用一些ASP.Net Ajax JavaScript魔术来操作UpdatePanel中的HTML。如果在更新的HTML中添加JavaScript代码,它将不会被执行


为什么不使用CustomValidator来验证您的复选框呢?

据我所知,UpdatePanel中的Ajax回发仅使用ASP.Net Ajax JavaScript魔术来操作UpdatePanel中的HTML。如果在更新的HTML中添加JavaScript代码,它将不会被执行


你为什么不使用CustomValidator来验证你的复选框呢?

你可以按照建议去做

你可以按照建议去做

我也在寻找同样的解决方案,因为我遇到了同样的问题。下面的方法对我来说就像@Sids建议的那样有效

ScriptManager.RegisterClientScriptBlock(myControl, myControl.GetType(), "msg", "alert('Success')", true);

我也在寻找同样的解决方案,因为我有同样的问题

ScriptManager.RegisterClientScriptBlock(myControl, myControl.GetType(), "msg", "alert('Success')", true);

@Im Hari:为什么不尝试异步自动回发,并检查其是否工作@Im Hari:为什么不尝试异步自动回发,并检查其是否工作