質問

I have created a listbox which is populated from a db. Using modal popup and panels, this listbox appears when the select user button is clicked. When a specific user is selected from this list and the add user button is clicked, I would like to populate the labels with the specific user name and userId. I cant seem to get the labels populated. It works when i dont use modal popup. Any ideas??? my code:

<asp:Label ID="UserId" runat="server"></asp:Label>
            <asp:Label ID="UserName" runat="server" Font-Bold="true" ForeColor="#97b23c" Font-Size="14px"></asp:Label>               
                <br />                
                <asp:Button ID="SelectUserBtn" runat="server" Text="Select User" />
                 </asp:Panel>
            </td>
            <td>

                <asp:Panel ID="Pnl" runat="server">
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <h4>List Of Available Users</h4>
                    <asp:ListBox ID="SourceList" runat="server" DataSourceID="SqlDataSource1" 
                        DataTextField="FullName" DataValueField="UserId" Height="160" Width="200"></asp:ListBox><br />

                    <asp:Button ID="OKBtn" runat="server" Text="Add User" OnClick="OkBtn_Click" />
                    <asp:Button ID="CancelBtn" runat="server" Text="Cancel" /><br />

                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:dmsConStr %>" 
                        SelectCommand="SELECT [UserId], [FullName] FROM [UserProfiles]">
                    </asp:SqlDataSource>
                </asp:Panel>  
                  <asp:ModalPopupExtender ID="MPEUserList" runat="server" TargetControlID="SelectUserBtn" PopupControlID="Pnl" OkControlID="OKBtn" BackgroundCssClass="ModalBackground" DropShadow="true" CancelControlID="CancelBtn">
                  </asp:ModalPopupExtender> 

my code behind:

protected void OkBtn_Click(object sender, EventArgs e)
    {
        UserId.Text = SourceList.SelectedItem.Value;
        UserName.Text = SourceList.SelectedItem.Text;
    }
役に立ちましたか?

解決

Actually the ModalPopupExtender is preventing the form from postback. Just don't include OkControlID property and it should work well.

<asp:ModalPopupExtender runat="server"
    ID="MPEUserList" 
    TargetControlID="SelectUserBtn" 
    PopupControlID="Pnl" 
    BackgroundCssClass="ModalBackground" 
    DropShadow="true" 
    CancelControlID="CancelBtn">
</asp:ModalPopupExtender>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top