Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Returning Selected Grid Value to parent window

Returning Selected Grid Value to parent window

Scheduled Pinned Locked Moved ASP.NET
cssquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asim N
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • A Asim N

      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

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, I think you are a bit confused here between the onclick event and the OnItemCommand event. Basically, the onclick event is the client side event that can run on the client machine. Meanwhile, the OnItemCommand is the server side event that only runs on the server. In this case, instead of adding the client side script block to the OnItemCommand event, you simply use one of utility methods[^] supported by the Page class to emit the script block.

      A 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, I think you are a bit confused here between the onclick event and the OnItemCommand event. Basically, the onclick event is the client side event that can run on the client machine. Meanwhile, the OnItemCommand is the server side event that only runs on the server. In this case, instead of adding the client side script block to the OnItemCommand event, you simply use one of utility methods[^] supported by the Page class to emit the script block.

        A Offline
        A Offline
        Asim N
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • A Asim N

          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

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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.

          A 1 Reply Last reply
          0
          • M minhpc_bk

            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.

            A Offline
            A Offline
            Asim N
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups