Professional Documents
Culture Documents
Passing Value From Popup Window To Parent Form TextBox
Passing Value From Popup Window To Parent Form TextBox
Page 1 of 2
--- .aspx of popup form --<script language="javascript"> function GetRowValue(val) { window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox2").value = val; //hardcoded value used to minimize the code. ControlID can be passed as query string to the popup window window.close(); } </script> . . . <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="400px"
http://weblogs.asp.net/farazshahkhan/archive/2008/02/16/passing-value-from-popup-wind...
7/10/2009
Passing value from popup window to parent form's TextBox - Faraz Shah Khan
Page 2 of 2
AllowPaging="True"> <Columns> <asp:TemplateField> <AlternatingItemTemplate> <asp:Button ID="btnSelect" runat="server" Text="Select" /> </AlternatingItemTemplate> <ItemTemplate> <asp:Button ID="btnSelect" runat="server" Text="Select" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> --- .vb file if vb.net is the language --Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If (e.Row.RowType = DataControlRowType.DataRow) Then DirectCast(e.Row.FindControl("btnSelect"), Button).Attributes.Add("onclick", "javascript:GetRowValue('" & e.Row.Cells(1).Text & "')") 'assuming that the required value column is the second column in gridview End If End Sub --- .cs file if C#.net is the language --protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { if ((e.Row.RowType == DataControlRowType.DataRow)) { ((Button)e.Row.FindControl("btnSelect")).Attributes.Add("onclick", "javascript:GetRowValue('" + e.Row.Cells(1).Text + "')"); //assuming that the required value column is the second column in gridview } }
I hope the code above is straight forward and easy to understand. Happy Coding!!!
http://weblogs.asp.net/farazshahkhan/archive/2008/02/16/passing-value-from-popup-wind...
7/10/2009