来自asp.net用户控件c#.net背后的代码的Javascript调用问题. [英] Javascript calling problem from code behind asp.net User Control, c#.net.

查看:75
本文介绍了来自asp.net用户控件c#.net背后的代码的Javascript调用问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在单击按钮时在运行时调用Javascript确认对话框.我可以在onclientclick上调用它,但是我的问题是我想在对按钮单击后的代码进行一些处理后再调用它.

另外,我在代码设计中使用了UpdatePanel,而我希望在我的自定义用户控件上使用它.我还使用母版页做一件事.请检查我下面的示例代码.

Hi,

I want to call Javascript confirm dialog box at runtime on my button click. I can call it onclientclick but, my problem is i want to call it after some processing on button click in code behind.

Also, I have used UpdatePanel in my code design and this I want on my custom User Control. One more thing I am also using Master Page. Please check my below sample code.

protected void btnSkipRecord_Click(object sender, EventArgs e)
   {
       if(reader.read())
{
string scriptString = @"<SCRIPT language='javascript'> return confirm('" + msg + "')</SCRIPT>";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "StartUp", scriptString, false);
}



我已经调试了代码,其执行没有错误,但是没有显示确认消息.有什么解决办法,然后请指导我.



I have debugged the code and its executing without error but not displaying confirm message. Is there any solution then please guide me.

推荐答案



如果您在更新面板中使用用户控件,则此代码将无效.是的,这是正确的,此代码也不会给您任何错误.您需要检查是否通过"ScriptManager.GetCurrent(Me.Page).IsInAsyncPostBack"更新面板触发了按钮单击事件.如果是,则必须使用"ScriptManager.RegisterClientScriptBlock"代替"Page.ClientScript.RegisterClientScriptBlock"
注册javascript.
谢谢
Hi,

If you are using your user control in your update panel, This code won''t work. Yes that is correct this code won''t give you any error also. You need to check that whether your button click event is fired via update panel with "ScriptManager.GetCurrent(Me.Page).IsInAsyncPostBack". If it is then you have to register javascript with the use of "ScriptManager.RegisterClientScriptBlock" in place of "Page.ClientScript.RegisterClientScriptBlock"

Thanks


这篇关于来自asp.net用户控件c#.net背后的代码的Javascript调用问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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