zoukankan      html  css  js  c++  java
  • asp.net Page.Controls对象(找到所有服务器控件)

    前台

    复制代码 代码如下:

    <%@ 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>无标题页</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div id="div1">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    </form>
    </body>
    </html>


    后台

    复制代码 代码如下:

    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    string name = "tree";
    //Server.Transfer("ajax.aspx?id=1&name="+name);
    ChangeControls();
    }
    /************Controls属性************
    * this.Controls则包括所有控件。
    * System.Web.UI.LiteralControl
    System.Web.UI.HtmlControls.HtmlHead
    System.Web.UI.LiteralControl
    System.Web.UI.HtmlControls.HtmlForm
    System.Web.UI.LiteralControl
    * 为<div id="div1">加上runat属性,则Form.Controls里则找不到Button1
    */
    private void ChangeControls()
    {
    foreach (System.Web.UI.Control control in this.Form.Controls)
    {
    if (control is Button)
    {
    Button btn = (Button)control;
    btn.Text = "Hello";
    }
    }
    foreach (Control control in this.Controls)
    {
    Response.Write(control.ToString() + "<br/>");
    }
    }
  • 相关阅读:
    java优雅的使用elasticsearch api
    springboot mybatis优雅的添加多数据源
    java通过shield链接Elasticsearch
    java spark-streaming接收TCP/Kafka数据
    hiveQL求差集
    hiveQL去重
    Ubuntu16.04+Opencv3.3的安装教程
    TensorFlow池化层-函数
    TensorFlow激活函数+归一化-函数
    TensorFlow图像预处理-函数
  • 原文地址:https://www.cnblogs.com/asdyzh/p/9746612.html
Copyright © 2011-2022 走看看