从父页面设置UserControl控件的可见性 [英] Set visibilty of controls of UserControl from parent page

查看:69
本文介绍了从父页面设置UserControl控件的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在用户控件中有3个按钮.我必须在gridview rowediting事件中设置其可见性,gridview在父页面中.我已经写了
像这样的代码

Hi,

I have 3 buttons in usercontrol. I have to set their visibility in gridview rowediting event, the gridview is in parent page.I have written
the code like this

protected void grdEventSchedule_RowEditing(object sender, GridViewEditEventArgs e)
   {
       WebUserControl uc = (WebUserControl)Page.LoadControl("DateTimeControl.ascx");
       Button btnAddSession = (Button)uc.FindControl("btnOK");
       btnAddSession.ID = "btnOK";
       Button btnUpdateSession = (Button)uc.FindControl("btnUpdate");
       btnUpdateSession.ID = "btnUpdate";
       Button btnCancel = (Button)uc.FindControl("btnCancel");
       btnCancel.ID = "btnCancel";
       btnAddSession.Visible = false;
       btnUpdateSession.Visible = true;
       btnCancel.Visible = true;

   }



但它们不可见.我在这里做错了什么.我是否需要在Page_Load事件中访问这些控件并在rowediting事件中设置它们的可见性?

谁能帮我吗



but they are not visible.what is wrong I am doing here. Do i need to access these controls in Page_Load event and set their visibility in rowediting event?

Can anyone please help me

推荐答案

您在这里所做的是加载用户控件并更改可见性.实际上,这还不完整,因为用户控件也应该绑定到表单上的现有元素.

您应该挂钩到现有的(已经加载的控件)并在此更改可见性.
What you are doing here is loading the user control and changing the visibility. In fact, that is also not complete as the user control should also be bound to existing element on the form.

You should get the hook to the existing (already loaded control) and change the visibility there.


这篇关于从父页面设置UserControl控件的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆