Asp.net page. Controls object (find all server controls)

Source: Internet
Author: User

Instance 1:
Front-end CopyCode The Code is as follows: <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div id = "div1">
<Asp: button id = "button1" runat = "server" text = "button" onclick = "button#click"/>
</Div>
</Form>
</Body>
</Html>

BackgroundCopy codeThe Code is as follows: public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}< br> protected void button#click (Object sender, eventargs e)
{< br> string name = "Tree";
// server. transfer ("Ajax. aspx? Id = 1 & name = "+ name);
changecontrols ();
}< br>/************** controls attributes *************
* This. controls includes all controls.
* system. web. UI. literalcontrol
system. web. UI. htmlcontrols. htmlhead
system. web. UI. literalcontrol
system. web. UI. htmlcontrols. htmlform
system. web. UI. literalcontrol
* adds the runat attribute to

, then form. button1
*/
private void changecontrols ()
{< br> foreach (system. web. UI. control in this. form. controls)
{< br> If (control is button)
{< br> button BTN = (button) control;
BTN. TEXT = "hello";
}< BR >}< br> foreach (Control in this. controls)
{< br> response. write (control. tostring () + "
");
}< BR >}

Related Article

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.