Asp.net 2.0 Application Development Technology Note 02

Source: Internet
Author: User
Chapter 2 ASP. NET 2nd server controls

1. It is worth noting that the htmlinputbutton control can execute the server-side click event, which must be noted as onserverclick. The default onclick event is a client event.
Web server controls Opposite The onclick event is a server event. to execute a client event, specify the event as an onclientclick event.
2. When using HTML server controls (the same as Web server controls), please note that Clientid and uniqueid In the master page, custom controls and control nesting, pay special attention to their meaning and usage.
The following example describes the meanings and rules of these tables. <% @ Import namespace="System. Data"  %>
<% @ Page Language = " C # " Codebehind = " Webform3.aspx. CS " Autoeventwireup = " False " Inherits = " Incentive2008.webform3 "   %>
< Html >
< Head >
< Title > Webform3 </ Title >
< Script Runat = "Server" >
Void Page_load (Object sender, system. eventargs E)
{
If ( ! Page. ispostback)
{
Datatable dt = New Datatable ();
Datarow Dr;
DT. Columns. Add ( New Datacolumn ( " Buttonvalue " , Typeof (String )));
For ( Int I = 0 ; I < 3 ; I ++ )
{
Dr = DT. newrow ();
Dr [ 0 ] = " Button " + I. tostring ();
DT. Rows. Add (DR );
}
Repeater1.datasource = New Dataview (DT );
Repeater1.databind ();
}
}
Void Submitemailclick (Object sender, eventargs E)
{
Message. Text = " <Li> name attribute value of htmlinputcontrol: " + (Htmlinputcontrol) sender). Name;
Message. Text = " <Li> ID attribute value of htmlinputcontrol: " + (Htmlinputcontrol) sender). ID;
Message. Text = " <Li> uniqueid attribute value of htmlinputcontrol: " + (Htmlinputcontrol) sender). uniqueid;
Message. Text = " <Li> clientid attribute value of htmlinputcontrol: " + (Htmlinputcontrol) sender). clientid;
Message. Text = " <Li> attribute value of namingcontainer of htmlinputcontrol: " + (Htmlinputcontrol) sender). namingcontainer. uniqueid;
Message. Text = " <Li> parentid attribute value of namingcontainer of htmlinputcontrol: " + (Htmlinputcontrol) sender). namingcontainer. Parent. ID;
}
</ Script >
</ Head >
< Body Ms_positioning = "Gridlayout" >
< Form ID = "Form1" Method = "Post" Runat = "Server" >
< ASP: Repeater ID = "Repeater1" Runat = "Server" >
< Itemtemplate >
< Input ID = "Submit1" Type = Submit Name = "Addbutton" Value = '<% # Eval ("buttonvalue") % > 'Onserverclick = "submitemailclick" runat = Server>
</ Itemtemplate >
</ ASP: Repeater >
< BR >
< BR >
< ASP: Label ID = "Message" Runat = "Server"   />
</ Form >
</ Body >
</ Html >

Run the preceding Program To view Source code You can see that although the ID and name attributes are specified for the button, the client ID and name are not
The Source Code As follows: < Input Name = "Repeater1 $ ctl0 $ submit1" ID = "Repeater1 _ ctl0_submit1" Type = "Submit" Value = "Button 0"   />
< Input Name = "Repeater1 $ ctl1 $ submit1" ID = "Repeater1 _ ctl1_submit1" Type = "Submit" Value = "Button 1"   />
< Input Name = "Repeater1 $ ctl2 $ submit1" ID = "Repeater1 _ ctl2_submit1" Type = "Submit" Value = "Button 2"   />

Name attribute value of htmlinputcontrol: repearter1 $ ctl002 $ submit1;
Id attribute value of htmlinputcontrol: submit1;
The uniqueid attribute value of htmlinputcontrol: repearter1 $ ctl002 $ submit1;
Clientid attribute value of htmlinputcontrol: repearter1_ctl002_submit1;
The uniqueid attribute value of namingcontainer of htmlinputcontrol: repearter1 $ ctl002;
The parentid attribute value repearter1 of namingcontainer of htmlinputcontrol:

Therefore, when writing a client program, do not use the specified id value to reference the object on the client. You must use the clientid attribute of the object to pass the reference to the client.
As shown in the preceding example, the naming rules for the name attribute and uniqueid attribute are separated by "$", while the clientid attribute is separated,
What does repeater1 and ctl001 mean? If trace is set to true in the page command, you can see the control tree when ASP. NET parses the page.
Figure: The naming rule is composed of the ID of the namecontainer control and the value of the Control ID (Note: it is not necessarily the ID of the parent control ). Server
The uniqueid of the control is displayed in the name attribute of the client, and the clientid is displayed in the ID attribute of the customer point. ForRequest. FormIn the form
It is very important to know the client data.

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.