Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 a label with the specific user name. I cant seem to get the label populated. Everything else works. Any ideas???

this is my asp 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 ID="Pnl" runat="server">
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                <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:sos_dmsConStr %>"
                        SelectCommand="SELECT [UserId], [FullName] FROM [UserProfiles]">
                  <asp:ModalPopupExtender ID="MPEUserList" runat="server" TargetControlID="SelectUserBtn" PopupControlID="Pnl" OkControlID="OKBtn" BackgroundCssClass="ModalBackground" DropShadow="true" CancelControlID="CancelBtn">

my code behind:
protected void OkBtn_Click(object sender, EventArgs e)
        UserId.Text = SourceList.SelectedItem.Value;
        UserName.Text = SourceList.SelectedItem.Text;
Rockstar_ 29-May-13 0:21am    
Yes, in the button click only set the label text property to the username or user id....
Rockstar_ 29-May-13 0:34am    
Put the label in another panel and try to call that panel by ModalPopUpextender by add button click event.

Hi Friend,
Please try the above by using bellow javascript function.

function Sayok() {
var dpt = document.getElementById("SourceList");

document.getElementById("UserId").innerHTML = dpt.options[dpt.selectedIndex].value;


into the button ok call js
here is the code

<asp:button id="OKBtn" runat="server" text="Add User" onclientclick="Sayok();" onclick="OkBtn_Click" xmlns:asp="#unknown">
Share this answer
Rockstar_ 29-May-13 0:44am    
How could he can call the JS before adding the item, after selecting the item from the listbox can only display the item in pop up not before selecting the item.....
damokk 29-May-13 5:30am    
tried it. Doesn't work. Its a problem with the panels and modal popup. it works perfectly when I place the listbox in a table on the page rather than a panel. The onclick event doesnt seem to carry the values from the popup/panel to the label. Any ideas??
It was the OkControlID that was preventing postback. I just removed it and it works now.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900