In asp.net use JavaScript display information Hint window implementation principle and code _ Practical skills

Source: Internet
Author: User

In asp.net use JavaScript to display the Information window, you can download a DLL from the Insus.net blog and place it in the site's Bin directory.
Download Address
Create an ASPX page, and then do several actions in the. Aspx.cs, one is to reference the namespace, instantiate the object.

Then write the JavaScript script in the Page_Load event:

Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
String message = "Welcome, insus.net!";
StringBuilder sb = new StringBuilder ();
Sb. Append ("Window.onload=function () {");
Sb. Append ("alert (')");
Sb. Append (message);
Sb. Append ("')};");

Js. Runjavascript (sb.) ToString ());
}

When a Web page is Page_Load, or when a Web page reloads, it displays a small window of information that results:

Next, Insus.net implements another situation, that is, when the user clicks the Ammonium button, the prompt window is displayed.

We put a button on the Web page:

Copy Code code as follows:

<asp:button id= "Button1" runat= "Server" text= "Submit" onclick= "Button1_Click"/>

Write the onclick event in. Aspx.cs:
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
String message = "Processing your request."
StringBuilder sb = new StringBuilder ();
Sb. Append ("alert (')");
Sb. Append (message);
Sb. Append ("');");

Js. Runjavascript (sb.) ToString ());
}

Try to run a look:

The final example is when a user clicks on the Ammonium button to make a confirmation prompt, which is a choice. After confirmation, the data is not actually submitted or processed.

The way to implement this is to write the following code in the Page_Load event on top of the second example environment above:

Copy Code code as follows:

View Code

protected void Page_Load (object sender, EventArgs e)
{
String message = "Do you want to submit it?" ";
StringBuilder sb = new StringBuilder ();
Sb. Append ("return confirm");
Sb. Append (message);
Sb. Append ("');");

Clientscript.registeronsubmitstatement (this. GetType (), "Alert", sb. ToString ());
}

Get the final effect:

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.