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: