zoukankan      html  css  js  c++  java
  • 获取母版中的控件

    1 通过findcontrol找控件ID
    需要在此事件中~因为Page_load中时是先内容页加载然后才是母版页加载
    protected void Page_LoadComplete(object sender, EventArgs e)
    {
    Label2.Text = "现在时间是" + (Master.FindControl("Label1") as Label).Text;
    if (Request.QueryString["id"] == "dy")
    {
    (Master.FindControl("Image1") as Image).ImageUrl = "~/Images/ml0069.jpg";
    }
    }

    2 通过强引用

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
    <%@ MasterType VirtualPath="~/MasterPage.master" %>

    然后可以在母版页中定义公共属性或方法
    public string GetUserName()
    {
    return Page.User.Identity.Name;
    }
    在内容页中调用
    Label1.Text = "欢迎光临" + Master.GetUserName();

    ================================================

    1、如何在后台代码中设置和获取用户控件中的子控件的属性?

    UserControl c = (UserControl)FindControl("YourUserControlID");

    TextBox tb = (TextBox) c.FindControl("YourTextBoxIDInYourUserControl);

    tb.Text = "123";

    2、如何在后台设置和获取用户控件本身的属性?

    YourUserControlID.Property1 = "123";

    获取模板页里用户控件里的控件

    control_left2 c = (control_left2)Master.FindControl("Left2_1");
    ((Label)c.FindControl("Label1")).Text = model.CompanyPoint.ToString();

  • 相关阅读:
    js yui
    ie tbody table 兼容方法
    js json ie不支持json
    js ie 6,7,8 使用不了 firstElementChild
    js for in
    js json 单双引号互换
    html table 上移下移
    js autoComplate
    开发总结
    CentOS6.7 下安装git
  • 原文地址:https://www.cnblogs.com/WarBlog/p/4444609.html
Copyright © 2011-2022 走看看