Returning Selected Grid Value to parent window
-
Hello, I was trying to return the selected grid value to parent window, but some problems in this. Here is some code: On Parent Form : Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx');") On Child i am trying to do things like : btnOK.Attributes.Add("onclick", "window.opener.Form1.txtValue.value = '" + txtValue.Text + "'") - Works in case of ordinary values. i want to have value returned whenever Select Button is selected in Grid Template column. Snippet is : If e.CommandName = "Select" Then txtValue.Text = DataGrid1.DataKeys.Item(e.Item.ItemIndex) DataGrid1.Attributes.Add ("OnItemCommand", "window.opener.Form1.txtValue.value = '" + txtValue.Text + "'") End If This is what i want i.e. value is returned to parent each time value is selected in gird - on child form. Please correct me where i am wrong? Waiting, Regards, Asim
-
Hello, I was trying to return the selected grid value to parent window, but some problems in this. Here is some code: On Parent Form : Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx');") On Child i am trying to do things like : btnOK.Attributes.Add("onclick", "window.opener.Form1.txtValue.value = '" + txtValue.Text + "'") - Works in case of ordinary values. i want to have value returned whenever Select Button is selected in Grid Template column. Snippet is : If e.CommandName = "Select" Then txtValue.Text = DataGrid1.DataKeys.Item(e.Item.ItemIndex) DataGrid1.Attributes.Add ("OnItemCommand", "window.opener.Form1.txtValue.value = '" + txtValue.Text + "'") End If This is what i want i.e. value is returned to parent each time value is selected in gird - on child form. Please correct me where i am wrong? Waiting, Regards, Asim
Hi there, I think you are a bit confused here between the
onclick
event and theOnItemCommand
event. Basically, theonclick
event is the client side event that can run on the client machine. Meanwhile, theOnItemCommand
is the server side event that only runs on the server. In this case, instead of adding the client side script block to theOnItemCommand
event, you simply use one of utility methods[^] supported by thePage
class to emit the script block. -
Hi there, I think you are a bit confused here between the
onclick
event and theOnItemCommand
event. Basically, theonclick
event is the client side event that can run on the client machine. Meanwhile, theOnItemCommand
is the server side event that only runs on the server. In this case, instead of adding the client side script block to theOnItemCommand
event, you simply use one of utility methods[^] supported by thePage
class to emit the script block. -
Ok, Thank you for guiding me. I was interested in returning value, once a select button in grid is clicked. So i was trying different things for achieving this. Anyway, still trying. Thanks. Regards, Asim
IMO, there are a couple of options to emi the script to return the value to the opener window. + Use your sample code above, and instead of adding the attribute to the OnItemCommand event, you simply emit the client script block that is supposed to run at the client side after the page is reloaded. + In the ItemCreated's event handler, you look for the select button and add the script block to the onlick event as you would with a normal button.
-
IMO, there are a couple of options to emi the script to return the value to the opener window. + Use your sample code above, and instead of adding the attribute to the OnItemCommand event, you simply emit the client script block that is supposed to run at the client side after the page is reloaded. + In the ItemCreated's event handler, you look for the select button and add the script block to the onlick event as you would with a normal button.
Thanks, i was able to work this out with following code : Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim objLinkBtn As LinkButton If e.Item.ItemType = ListItemType.AlternatingItem Or _ e.Item.ItemType = ListItemType.Item Or _ e.Item.ItemType = ListItemType.SelectedItem Then objLinkBtn = e.Item.FindControl("LinkButton1") If Not objLinkBtn Is Nothing Then objLinkBtn.Attributes.Add ("onclick", "javascript:window.opener.Form1.txtValue.value = '" + DataGrid1.DataKeys(e.Item.ItemIndex) + "'") End If End If End Sub Thats it. Regards, Asim