1

实际上我正在使用 asp.net 和 c# 开发模板。我的用户控件页面中有一个面板,其中包含 2 个字段集。我想从 main.aspx 页面后面的代码访问这两个字段集,这意味着当用户单击 main.aspx 页面上的 link1 时,面板将刷新并显示 fielset1,当用户单击 link2 时,面板将被刷新,面板显示 fieldset2。对于页面的部分刷新,我正在使用更新面板。你能指导我如何解决这个问题吗?感谢您的考虑。

4

1 回答 1

0

感谢 Denys 跟进。我已经解决了这个问题。
我在我的用户控件页面上放置了一个 HiddenField 变量:

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

然后我从 aspx.cs 页面访问并更改了它:

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

然后我在 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>

    <% } %>

我希望它会有所帮助。谢谢

于 2011-12-14T07:31:08.497 回答