Asp tutorial. net clientscript. registerclientscriptblock usage
The first is the ghost method of the registerstartups tutorial. When you want to start
This class is recommended for webpage special effect functions.
<% @ Page language = "c #" autoeventwireup = "true" codefile = "default. aspx. cs"
Inherits = "default" %>
<! Doctype html public "-// w3c // dtd xhtml 1.1 // en"
Http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: wizard id = "wizard1" runat = "server">
<Wizardsteps>
<Asp: wizardstep runat = "server" title = "step 1">
& Nbsp; <asp: textbox id = "textbox1" runat = "server"
> </Asp: textbox>
<Asp: button id = "button1"
Runat = "server" text = "button"
Onclientclick = "test ()"/>
& Nbsp;
</Asp: wizardstep>
<Asp: wizardstep runat = "server" title = "step 2">
</Asp: wizardstep>
</Wizardsteps>
</Asp: wizard>
</Div>
</Form>
</Body>
</Html>
File: default. aspx. cs
Using system;
Using system. data;
Using system. configuration;
Using system. collections;
Using system. web;
Using system. web. security;
Using system. web. ui;
Using system. web. ui. webcontrols;
Using system. web. ui. webcontrols. webparts;
Using system.web.ui.html controls;
Public partial class default: system. web. ui. page
{
Protected void page_load (object sender, eventargs e)
{
String jscript =
"<Script language = javascript> n" +
"<! -- N "+
"Function test () n" +
"{N" +
"Var what = document. forms ['form1 ']; n" +
"If (! What) {n "+
"What = document. form1; n" +
"} N" +
"If (what." + this. textbox1.clientid + ". value ='') n "+
"{N" +
"Alert ('You entered: nothing! '); N "+
"} N" +
"Elsen" +
"{N" +
"Alert ('You entered: '+ what." + this. textbox1.clientid +
". Value);" +
"} N" +
"} N" +
"// --> </Script> n ";
Clientscript. registerclientscriptblock (typeof (page), "test", jscript );
}
}
Adding javascript to a specific server control on the asp.net tutorial page is very simple. Me
Take the button server control as an example. If you use any of the microsoft visual studio 2005
Drag the button html Server Control (htmlinputbutton class) to a page and use it
The following code structure is required for running the server control:
<Input id = "button1" type = "button" value = "button" runat = "server"/>
This is a common button, which can be programmed through code separation on the asp.net page or server-side scripts.
Control it. For example, to specify the button text when a page is generated, you only need to change the element to html server.
Server control (right-click the control and select run as server control (as a server control)
Run) and then use the value Attribute of the button.