ASP.net pop-up message dialog box Method! (download)
Source: Internet
Author: User
Principle
Place a hidden control on the page and place a script code at the end of the page, and the script code detects whether the value of the hidden control is empty, and if it is not empty, the pop-up dialog box displays the information or does nothing.
The background code modifies the value of the hidden control when it is needed so that when the page is uploaded to the user, the final script code executes and pops up the dialog box.
"Precautions"
1. The hidden control must be an HTML control, otherwise JavaScript cannot be found.
2. Background code to modify the value of the hidden control, the hidden control naturally has to add runat= "server" tag.
3. After the pop-up dialog box, remember to put the value of the hidden control empty, otherwise the refresh will bounce out again.
4. The script code must be placed behind the hidden control, otherwise it cannot be found.
Achieve
Page code (only body listed)
< body ms_positioning = "GridLayout" >
< form ID = "Form1" method = "post" runat = "server" >
< Asp:textbox ID = "Manuinput" runat = "server" ></asp:textbox >
< Asp:button ID = "Button1" runat = "server" Text = "dialog box" ></Asp:button >
< INPUT ID = "Passtxt" type = "hidden" runat = "server" > <! -Hide Controls à
</form >
< script language =javascript > ...
if (document.all ("Passtxt"). value!= "")
... {
Alert (document.all ("Passtxt"). Value);
document.all ("Passtxt"). value= ""; That's not a thing to lose.
}
</script >
</Body >
Background code (list of Button1 response events only)
private void Button1_Click (object sender, System.EventArgs e)
{
Passtxt.value = Manuinput.text;
}
Effect
"Supplementary Notes"
In fact, this method is very simple, but it is very effective, you can write a function ShowDialog (string str), and then in the background code where any need to call to pop-up dialog box.
In addition, you can change alert to Showmodeldialog () to eject a richer, more beautiful window.
Finally, it must be explained that the idea of this method can be used to pass information between the script and the background code, as I did in my Web application, which worked well.
During the development of the ASP.net program, we often need to give the user the prompt information, such as whether "successful operation", "OK" or "Cancel" operation.
(1) Click on the button on the page, pop-up a dialog box prompts "OK" or "Cancel" operation, we use the button to add properties to complete:
Cases:
Public System.Web.UI.WebControls.Button Btndelrow;
BTNDELROW.ATTRIBUTES.ADD ("onclick", "return confirm (' OK to delete? ');");
(2) Click on the link on the page, pop-up a dialog box prompt is "OK" or "Cancel" operation, you can in the Page_Load () event, give you want to give confirmation prompts the button to add properties:
Cases:
LINK.ATTRIBUTES.ADD ("onclick", "return Confirm" (' You want to perform this operation?) ');");
(3) After a page completes an operation, a pop-up dialog box prompts whether "successful operation."
Cases:
Response.Write ("< script > ... alert" (' Delete successful! ') </script > ");
(4) Allow ASP.net server controls to emit client script blocks in Page:
public virtual void RegisterStartupScript (string key,string script);
Cases:
if (!this. isstartupscriptregistered ("Hello"))
This. RegisterStartupScript ("Hello", "< script > ... alert (' Hi! ') </script >");
The OK dialog box pops up:
Response.Write ("< Script Language =javascript > ... alert" message. '); </Script > ");
Pop-up "OK" dialog box, click on the jump page:
Response.Write ("< Script Language =javascript > ... alert" message. '); Window.navigate ('.. /index.aspx '); </Script > ");
Eject the OK and Cancel dialog box, and then click OK to perform the relevant actions:
Method One: In the Page_Load event, write the button1.attributes["OnClick"]= Javascript:return confirm (' Are you sure you want to delete it? '), and then write your execution code in the Button1_onclick event.
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.