简体   繁体   English

如何从main.aspx页面的代码后面访问usercontrol.ascx中的字段集?

[英]how to access fieldset in usercontrol.ascx from codebehind of the main.aspx page?

actually i'm developing template using asp.net and c#. 实际上我正在使用asp.net和c#开发模板。 i have one panel which contain 2 fieldset in my usercontrol page. 我有一个面板,其中包含2个我的用户控件页面中的字段集。 i wand to access these 2 fieldset from the code behind of the main.aspx page, which means when the user click on the link1 at the main.aspx page the panel will be refresh and shows the fielset1 and when the user click on the link2, the panel will be refresh and panel shows the fieldset2. 我想从main.aspx页面后面的代码访问这2个字段集,这意味着当用户单击main.aspx页面上的link1时,面板将刷新并显示fielset1以及当用户单击link2时,面板将刷新,并且面板显示fieldset2。 for the partial refreshing of the page i'm using the updatepanel. 对于页面的部分刷新,我正在使用updatepanel。 could you please guide me how to get ride of this problem. 你能指导我如何解决这个问题吗? appreciate your consideration. 感谢您的考虑。

thanks Denys for following up. 感谢Denys的跟进。 i have fix the problem. 我已经解决了这个问题。
i have put one HiddenField variable at my usercontrol page: 我在我的usercontrol页面上放了一个HiddenField变量:

<asp:HiddenField ID="hid_choosingField" Value="" runat="server" />

then i have accessed and changed it from aspx.cs page: 那么我已经从aspx.cs页面访问并更改了它:

Control hidField = WebUserControl31.FindControl("hid_choosingField");
    HiddenField ucHidField = (HiddenField)hidField;
    ucHidField.Value = "1";

then i have put a if condition at the ascx page to check what is the HiddenField value and base on the value i show the related fieldset: 然后我在ascx页上放置了if条件,以检查什么是HiddenField值,并根据该值显示相关的字段集:

<% if (hid_choosingField.Value == "1")
   { 
%>
    <fieldset id="uc3Fieldset1" style=" height:350px;">
    <legend>New Module Details</legend>

        <asp:Label ID="Label2" runat="server" ForeColor="blue" Text="This is User Control 3 Panel 1 Fieldset 1" />
    </fieldset>

    <%}
   else if (hid_choosingField.Value == "2")
   { %>

    <fieldset style=" height:350px;">
    <legend>New Module Details</legend>

        <asp:Label ID="Label1" runat="server" ForeColor="blue" Text="This is User Control 3 Panel 1 Fieldset 2" />
</fieldset>

    <% } %>

i hope it would be helpful. 我希望这会有所帮助。 thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM