在Web表单的消息框中单击“确定"时,整个页面都会刷新 [英] whole page gettin g refreshed when click ok in message box in web form

查看:67
本文介绍了在Web表单的消息框中单击“确定"时,整个页面都会刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我遇到了很奇怪的问题.我有一个模型pop扩展程序,正在让用户填充其中的字段.因此,如果用户错过了某些字段/文本框,我希望在消息框中相应地生成一条消息.但是,成功发生了,但是当我在消息框中单击确定"时,整个页面都被刷新并隐藏了弹出窗口.比起我必须再次返回并重复该过程.我想念什么吗?请帮忙.这是我的消息框代码:

Hi,
I am getting very weird problem. I have a model pop extender and I am making user to fill fields in it. So if user misses some field/text box I wanted a message to be generated accordingly in the message box. It happened succesfully however when i Click Ok in the message box than whole of the page gets refreshed and hides the pop up. Than I have to go back again and repeat the process. M i missing something ? Please help. Here is my code for message Box:

private void MessageBox(string msg)
  {
      // define a javascript alertbox containing
      // the string passed in as argument

      // create a new label
      Label lbl = new Label();

      // add the javascript to fire an alertbox to the label and
      // add the string argument passed to the subroutine as the
      // message payload for the alertbox
      lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";

      // add the label to the page to display the alertbox
      Page.Controls.Add(lbl);
  }

推荐答案



我会说不用添加此标签,而只需设置modalpopup扩展程序标签值并显示 modelpopup扩展程序使用show()方法,确保将onClientClick = return设置为false或将该按钮设置为modalpopup扩展程序的okcontrolid

否则,您也可以注册启动脚本,因为在页面中使用Ajax时,您需要使用scriptmanager.registerstartupscript,请参考
Hi,

I would say instead of adding this label you just set the modalpopup extender label value and show modelpopup extender using the show() method, make sure to set onClientClick=return false or set that button as okcontrolid for modalpopup extendar

Or else you can register startup script also, as you are using ajax in your page you need to user scriptmanager.registerstartupscript, pls refer ScriptManager.RegisterStartupScript


此弹出消息框应显示在Page_ Unload 中,以使其正常工作.

查看此链接.它具有有效的messagebox 类.使用它或参考代码来解决您的问题.

用于ASP.NET网站的类似于MessageBox的Windows窗体 [ ^ ]
This popup message box should be shown in Page_Unload to make it work without any problems.

check out this link. it has a working messagebox class. use it or refer the code to solve your problem.

A Windows Form like MessageBox for ASP.NET Website[^]


这篇关于在Web表单的消息框中单击“确定"时,整个页面都会刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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