Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datalist to display Listof Product.
When user click on any of the product a Pop-up will open with
a Label(ProductName), a textbox and a OkButton. Upto here it is working.
But I am unable to get the user input from the textBox after clicking OK button.
It is returning the initial default value of textbox every time.

-------------------------------------------------------------------------------------------

XML
<asp:DataList ID="DataList1" runat="server"
            onitemdatabound="DataList1_ItemDataBound">

        <asp:LinkButton ID="LinkButton1" runat="server" Text ='<%# Bind("pro_Name")%>'></asp:LinkButton>
        <asp:Panel ID="panel_Popup" runat="server" Width ="200" Height ="200" style ="background-color :Lime; display :none ">
            <asp:Label ID="lblProduct" runat="server" Text='<%# Bind("pro_Name")%>'></asp:Label>
            <asp:TextBox ID="ModelTxt" runat="server" TextMode ="SingleLine" Text ="Enter a Text"></asp:TextBox>
            <asp:Button ID="OkButton" runat="server" Text="Ok" />
            <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
        </asp:Panel>
        <cc1:ModalPopupExtender ID="ModalPopupExtender2"  runat="server" TargetControlID ="LinkButton1"
        PopupControlID ="panel_Popup" BackgroundCssClass ="modelbackground" OkControlID ="OkButton"
        CancelControlID ="CancelButton" >


        </asp:DataList>
----------------------------------------------------------------------------------------
 protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        switch (e.Item.ItemType)
        {
            case ListItemType.AlternatingItem:
            case ListItemType.Item:
                 Button btn = (Button)e.Item.FindControl("OkButton");
                TextBox txt = (TextBox)e.Item.FindControl("ModelTxt");
                btn.Attributes.Add("onclick", "alert('" + txt.Text + "'); return false;");
                break;
        }
    }
-----------------------------------------------------------------------------------------


Please help me to populate a perfect popup window to accept user input for the datalist items.
Posted
Updated 18-Feb-11 19:32pm
v2

1 solution

Hi

You are assign the current txt value to the alert in a static way. Javascript run at client side. So change your code to

btn.Attributes.Add("onclick", "alert(document.getElementById('" + txt.ClientID + "').value); return false;");

to get the value dynamically

To get the values of the ModelTxt box entered in the pop can be get in the code behind on the submit event. Once press the submit button (add a asp:button control to the aspx and in its click event)...have this code
C#
protected void Button1_Click(object sender, EventArgs e)
{
    Control ctrl=null;
    foreach (DataListItem Item in DataList1.Items)
    {
            ctrl = Item.FindControl("ModelTxt");

            if (ctrl !=null)
            {
                TextBox text1 = (TextBox)ctrl;
                string txt_entered_in_popup = text1.Text;
            }
        }



}
 
Share this answer
 
v2
Comments
SHAJANCHERIAN 20-Feb-11 8:55am    
It is displaying in the Alertbox. Can you tell me how can I get the value in a variable of code-behind.
Albin Abel 21-Feb-11 4:16am    
hi look at my improved answer. Data Item Bound is fire when a data is assigned to data list item. That time you are not entered anything in the pop up. These events happen before the page loaded fully. You can get the data from the popup in the form submiting
SHAJANCHERIAN 21-Feb-11 11:20am    
I did as you said. But in the variable "txt_entered_in_popup" I am getting the default value of text box, not able to get the value user enters.

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