且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在用户控制页面中访问另一个页面按钮控件

更新时间:2023-12-06 11:28:16

有几种方法可以做到这一点,但是如果你想在page_load中进行,那么你必须将按钮的属性暴露给页面:





MyControl.ascx.cs

  public   partial   class  MyControl:UserControl 
{
public bool MyButtonVisibility
{
set {MyButton.Visible = 值跨度>; }

}
}



MyPage.aspx.cs

  public   partial   class  MyPage:Page 
{
受保护 void Page_Load(对象发​​件人,EventArgs e)
{
如果(条件)
MyControl1.MyButtonVisibility = 假跨度>;
}
}







希望有所帮助^ _ ^

Andy


I have user control page as follows

 protected void Page_Load(object sender, EventArgs e)
{
    if (Session["CurrentUser"] == null)
    {
        Response.Redirect("Login.aspx");
    }
    if (!IsPostBack)
    {
        try
        {
            this.LstMinorCode.Visible = false;
            this.LstCrsDate.Visible = false;
            SQl = "select cmj_major_code,cmj_major_desc from co_major_master where cmj_active <> 'D'";
            Dr = SCon.ReadSql(SQl);
            this.DdlMajoreCode.DataSource = Dr;
            this.DdlMajoreCode.DataTextField = "cmj_major_desc";
            this.DdlMajoreCode.DataValueField = "cmj_major_code";
            this.DdlMajoreCode.DataBind();

            Dr.Close();
        }
        catch (Exception e1)
        {
            this.Label1.Text = e1.Message.ToString();
        }
    }
}

      I HAVE ANOTHER PAGE CONFIRMATION.ASPX as Follows

      protected void Page_Load(object sender, EventArgs e)
     {
        if (Session["CurrentUser"] == null)
            Response.Redirect("login.aspx");

       if (!IsPostBack)
         {
             Gettype();
         }
     }

     private void Gettype()
    {
   Sql = "select DISTINCT Type FROM Admin_Track";
   Dr = SCon.ReadSql(Sql);
   ddlType.Items.Clear();
   ddlType.DataTextField = "Type";
   ddlType.DataValueField = "Type";
   ddlType.DataSource = Dr;
   ddlType.DataBind();
   Dr.Close();
  }

   protected void btn_show_Click(object sender, EventArgs e)
   {

   }


in the user control page, in the page load i want to set visible the button true. This button in the CONFIRMATION page.

for that how can i do in asp.net using c#

There are a couple of ways to do this, but if you want to do it in page_load then you will have to expose the property of the button to the page:


MyControl.ascx.cs
public partial class MyControl: UserControl
{
   public bool MyButtonVisibility
   {
      set{ MyButton.Visible = value; }

   }
}


MyPage.aspx.cs

public partial class MyPage: Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      if(condition)
        MyControl1.MyButtonVisibility = false;
   }
}




Hope that helps ^_^
Andy