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();

  • 相关阅读:
    how to use epoll with python
    tornado ioloop current和instance的一些区别
    网络标准及路由器速度
    C语言接口

    Dalvik 与 ART
    Android学习笔记47-使用HttpClient接口实现网络通信
    Android学习笔记46-使用Post方式提交数据
    Android学习笔记45-JSON数据解析(GSON方式)
    Android学习笔记44-JSON数据解析
  • 原文地址:https://www.cnblogs.com/WarBlog/p/4444609.html
Copyright © 2011-2022 走看看