Implementation principle and code of the information display window using JavaScript in ASP. NET

Source: Internet
Author: User

In ASP. NET, use JavaScript to display information. You can download a DLL from the insus. Net blog and put it in the bin directory of the site.

Create An ASPX page and perform several actions in. aspx. cs. One is to reference the namespace and instantiate the object.

Then write the Javascript script in the page_load event:

CopyCode The Code is 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 ());
}

The page displays a small window of information when page_load or when the page is reloaded. effect:

Next, the implementation of insus. NET is another case. When you click the button, a prompt window is displayed.

We place a button on the webpage:

Copy code The Code is as follows: <asp: button id = "button1" runat = "server" text = "Submit" onclick = "button#click"/>

Write the onclick event in. aspx. CS:Copy codeThe Code is as follows: protected void button#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 ());
}

Test run:

In the last example, a confirmation prompt is provided when you click the button. After confirmation, data is submitted or processed.

The implementation method is to write the following code in the page_load event on the environment in the second example above:

Copy code The Code is as follows: view code

Protected void page_load (Object sender, eventargs E)
{
String message = "do you want to submit? ";
Stringbuilder sb = new stringbuilder ();
SB. append ("Return confirm ('");
SB. append (Message );
SB. append ("');");

Clientscript. registeronsubmitstatement (this. GetType (), "alert", SB. tostring ());
}

The final result is as follows:

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.