Click here to Skip to main content
16,016,460 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a ModelPopup & Popup-panel wihtin a Datalist-Itemtemplate.
Popup-panel contains TextBox, OkButton and CancelButton.
I need to get the input from the above TextBox on Ok-Button click
to my cod-behind for further processing.
--------------------------------------------------------------
JavaScript
<script type ="text/javascript" >
        function forOkbtn() 
	{
            //$find('panel_Popup').hide();//1st Problem :Javascript unable to find the control panel_Popup
            $get('DummyButton').click();//Redirect to click event of dummy-Asp:Button which outside of Datalist
        }
</script>

-----------------------------------------------------------------
//Code behind
C#
protected void DummyButton_Click(object sender, EventArgs e)
    {
        TextBox popupTxt = (TextBox)DataList1.FindControl("ModelTxt");//2nd Problem :Unable to find the TextBox: ModelTxt
        String PopupTextBoxValue = popupTxt.Text;
    }

-------------------------------------------------------------------
I know this is not a right way. Expecting a more straight forward way Or Suggest Correction in the above code
Posted
Updated 16-Feb-11 17:19pm
v2

1 solution

Hi,

Just add following code
C#
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            switch (e.Item.ItemType)
            {
                case ListItemType.AlternatingItem:
                case ListItemType.Item:
                    Button btn = (Button)e.Item.FindControl("DummyButton");
                    TextBox txt = (TextBox)e.Item.FindControl("ModelTxt");

                    btn.Attributes.Add("onclick", "alert('" + txt.Text + "'); return false;");
                    break;
            }
        }


Thanks,
Imdadhusen
 
Share this answer
 
Comments
SHAJANCHERIAN 17-Feb-11 5:25am    
Thanks .I have incorporated your code, Its working But.
Though I change the TextBox value and press OK button in popup, It still provide the initial TextBox Value. Iam furnishing entire code below ..
-------------------------------------------------------------------------------------------
<asp:DataList ID="DataList1" runat="server"
onitemdatabound="DataList1_ItemDataBound">
<itemtemplate>
<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;
}
}
-----------------------------------------------------------------------------------------

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