In recent project development, this is often the case when the user clicks on the button on the page, the system needs to pop a window. This window may be a standard dialog box or a new page. At first I didn't know how to implement such a feature, according to my previous programming habits, I think there should be a similar approach to showmessage, but unfortunately this method is not available under the Web. By looking through the data on the web, it was found that the usual practice was to write the following code in the button's OnClick event:
private void Button1_Click (object sender, System.EventArgs e)
{
String strscript = "<script language=javascript>/n";
Strscript + + "Window.alert" ("+"/"hello/" "+"); ";
Strscript + = "";
Response.Write (Strscript);
}
The effect of the above code is that when the user clicks on the Button1 button, a dialog box will pop up. The practice is to embed a section of JavaScript script files in your. cs file. However, I think you can see this code, may feel very uncomfortable, so many "" very easy to faint. If you need to eject a page, and you need to pass parameters, the code you write will feel more faint.
Later, I thought about whether I could put the script part in the. aspx file, and directly refer to the function name in the. cs. As it turns out to be possible, see the following implementation method:
1. Add this code before ASPX
< script language = "JScript" >
function ShowMessageBox ()
{
Window.alert ("Hello");
}
2. Add the following code in the Page_Load event of the CS file
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
this. BUTTON1.ATTRIBUTES.ADD ("onclick", "Javascript:showmessagebox ();");
}
3. Now when you click on the Button1 button on the page, the effect is similar to the previous method, but the entire system code looks much more comfortable
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.