Asp.net ClientScript. RegisterClientScriptBlock usage

Source: Internet
Author: User

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.

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.