0

我创建了一个 aspx 页面,我希望在其中根据用户选择启用一些控件。

如果用户选择All两个单选按钮应启用,否则隐藏。

我的声明部分是:

 <tr>
    <td>
        <asp:Label ID="lblCommunityMembers" runat="server" Text="Community Members" />
    </td>
    <td>

        <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        </asp:ScriptManagerProxy>
        <asp:UpdatePanel ID="upCommunityMembers" runat="server">
            <ContentTemplate>
                <asp:RadioButton ID="rdbCommunityMembersAll" runat="server" Text="All" GroupName="grpCommMembers" Checked="true" OnCheckedChanged="rdbCommunityMembersAll_CheckedChanged" AutoPostBack="true" />
                <asp:RadioButton ID="rdbCommunityMembersSelectedUsers" runat="server" Text="Selected Users" GroupName="grpCommMembers" OnCheckedChanged="rdbCommunityMembersSelectedUsers_CheckedChanged" AutoPostBack="true" />        
                <SharePoint:ClientPeoplePicker ID="ppCommunityMembers" runat="server" AllowMultipleEntities="true" AllowEmpty="false" Visible="false" />
            </ContentTemplate>

        </asp:UpdatePanel>

    </td>
</tr>
<tr>
    <td>
        <asp:Label ID="lblCommunityCatagory" runat="server" Text="Community Catagory" />
    </td>
    <td>
        <asp:DropDownList ID="ddlCommunityCatagory" runat="server">
            <asp:ListItem Value="0">---- Select One ----</asp:ListItem>
        </asp:DropDownList>
    </td>
    <td>
        <asp:RequiredFieldValidator ID="rfvCommunityCatagory" runat="server" InitialValue="0" ErrorMessage="Please Select Community Catagory"
             ForeColor="Red" ControlToValidate="ddlCommunityCatagory" Display="Dynamic" />
    </td>
</tr>
<tr>

    <td>
        <asp:Label ID="lblCommunityAccess" runat="server" Text="Required Approval?" Visible="false" />
    </td>
    <td>
        <asp:RadioButton ID="rdbRequiredApprovalYes" runat="server" Text="Yes" GroupName="grpCommMembers" Checked="true" Visible="false" />
        <asp:RadioButton ID="rdbRequiredApprovalNo" runat="server" Text="No" GroupName="grpCommMembers" Visible="false"/>        
    </td>        

</tr>

我背后的代码:

protected void rdbCommunityMembersSelectedUsers_CheckedChanged(object sender, EventArgs e)
    {
        if (rdbCommunityMembersSelectedUsers.Checked)
        {
            enableControls();


        }
        else
        {
            disableControls();

        }
    }

    protected void rdbCommunityMembersAll_CheckedChanged(object sender, EventArgs e)
    {
        if (rdbCommunityMembersAll.Checked)
        {
            disableControls();

        }
        else
        {
            enableControls();
        }
    }

    protected void enableControls()
    {
        ppCommunityMembers.Visible = true;
        lblCommunityAccess.Visible = true;
        rdbRequiredApprovalNo.Visible = true;
        rdbRequiredApprovalYes.Visible = true;
    }

    protected void disableControls()
    {
        ppCommunityMembers.Visible = false;
        lblCommunityAccess.Visible = false;
        rdbRequiredApprovalNo.Visible = false;
        rdbRequiredApprovalYes.Visible = false;
    }

如果社区成员被全部选中,那么“需要批准?” 部分应该被隐藏。

但问题是,当我选择选定的用户时,我只看到人员选择器控件可见,所需的批准控制没有显示。我错过了什么?

4

1 回答 1

0

您的单选按钮 rdbCommunityMembersAll 和 rdbCommunityMembersSelectedUsers 位于更新面板内,因此它们正在进行部分回发。要使控件在 UpdatePanel 之外可见,您可以执行以下任一操作:

  1. 将 rdbCommunityMembersAll 和 rdbCommunityMembersSelectedUsers 移到 UpdatePanel 之外

  2. 在 UpdatePanel 中移动需要使其可见的控件(lblCommunityAccess、rdbRequiredApprovalNo、rdbRequiredApprovalYes)

    或者

  3. 而不是设置 Visible="false",设置 style="display:none" 并通过 javascript/jquery 触发可见性

于 2013-10-09T14:36:52.643 回答