Open a new Window and pass it the variable recordid

I have a datagrid and would like to click on the edit button when I click the edit button I would like a popup page to open, smaller than the first and ontop of the existing page.   I would like to run a query when I open the page to fill in boxes from the recordId on the selected row.

I have 2 questions.

1.  How can I get the new page to open, currently I have  for the code in the body

<Columns>
  <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
      <asp:TemplateColumn>
      <HeaderTemplate>
      Name
      </HeaderTemplate>
      <ItemTemplate>
      <%# Container.DataItem("name") %>
      </ItemTemplate>
      <EditItemTemplate>
      <asp:TextBox id="txtName" runat="server" Text='<%# Container.DataItem("timeout") %>' />
      <asp:RequiredFieldValidator id="rfvName" Display="Dynamic" ErrorMessage="Name is required!" ControlToValidate="txtName"                  runat="server" />
      </EditItemTemplate>
      </asp:TemplateColumn>
      <asp:BoundColumn DataField="timein" HeaderText="Time In" ReadOnly="true" />
      <asp:BoundColumn DataField="timeout" HeaderText="Time out" ReadOnly="true" />
</Columns>

serverside code

Sub dg_Update(s As Object, e As DataGridCommandEventArgs)

      Dim intrecordid As Integer
      Dim strtimein As String
            
      intrecordid = dgAddressBook.DataKeys(e.Item.ItemIndex)
      strtimein = CType(e.Item.FindControl("txtName"), TextBox).Text      
      
      strCmd = "UPDATE Employeehours SET timeout=@timeout WHERE recordID=@recordID"
      objCmd = New SqlCommand(strCmd, objConn)
      objCmd.Parameters.Add("@timeout", strtimein)
      objCmd.Parameters.Add("@recordid", intrecordid)
      objConn.Open()
      objCmd.ExecuteNonQuery()
      objConn.Close()
      
      dgAddressBook.EditItemIndex = -1
      BindData()
End Sub


2.  How can I pass the recordId to the new page.

Thank you in advance.  I really appreicate the help!
running32Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jens FiedererTest Developer/ValidatorCommented:
You can use a regular <button> HTML control, like

<button onclick='window.open("popup.aspx?recordId=" + document.getElementById("storedRecordID"))'>

Jens FiedererTest Developer/ValidatorCommented:
Of course, you must have created a popup.aspx with your client/server side code,
and when it loads it picks the recordId from Request.Params("recordId")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SwapnilSoftware ArchitectCommented:
Hi,

Ans 1.

 You can do it by DataGrid.ItemCommand Event (following link is handling same event which u want )

http://authors.aspalliance.com/aspxtreme/sys/Web/ui/webcontrols/datagridclassitemcommand.aspx

you can

Ans 2.
you can get recordId from itemcommand itselft and pass it to other page like

session("recordId") = datagrid.items...
response.write("<script language="javascript"> window.open('pagename.aspx'); </script>")



and in pagename.aspx file
you can access your recordid through session.

Regards,
NetSwap


CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

running32Author Commented:
How can I make something llike this work.

<asp:HyperLinkColumn DataNavigateUrlField="recordid" DataNavigateUrlFormatString="javascript:window.open('popup.aspx?recordid={0}', '', 'width=200,height=100');" DataTextField="recordid"  HeaderText="Edit"></asp:HyperLinkColumn>

This code will open up a new window but the main window gives an error.

Thanks

NetSwap I get an error on response.write("<script language="javascript"> window.open('pagename.aspx'); </script>")
when I try to use your code.
                         
Jens FiedererTest Developer/ValidatorCommented:
What error do you get form the main window?

What is the code in popup.aspx?
running32Author Commented:
the main window just has a [object] in the top left hand corner and the rest of the page is white.

I don't have any code in my popup window yet as I am not sure what to put.

Thanks
Jens FiedererTest Developer/ValidatorCommented:
Perhaps you could use a trivial example:

main.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function popit(x) {
        window.open("popup.aspx?id=" + x);
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="id" />
                <asp:BoundField DataField="name" />
                <asp:TemplateField >
                <ItemTemplate>
                <button onclick='popit(<%# DataBinder.Eval(Container, "DataItem.id") %>)'>Foo</button>
                </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
Jens FiedererTest Developer/ValidatorCommented:
main.aspx.vb:

Partial Class _Default
    Inherits System.Web.UI.Page

    Structure st
        Public m_id As Integer
        Public m_name As String

        Public ReadOnly Property id() As Integer
            Get
                Return m_id
            End Get
        End Property

        Public ReadOnly Property name() As String
            Get
                Return m_name
            End Get
        End Property

    End Structure
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim l As New ArrayList(4)
        Dim s As New st
        s.m_id = 1
        s.m_name = "a"
        l.Add(s)
        s = New st
        s.m_id = 2
        s.m_name = "b"
        l.Add(s)
        s = New st
        s.m_id = 3
        s.m_name = "ceci"
        l.Add(s)
        s = New st
        s.m_id = 4
        s.m_name = "dada"
        l.Add(s)
        GridView1.DataSource = l
        GridView1.DataBind()
    End Sub
End Class
Jens FiedererTest Developer/ValidatorCommented:
popup.aspx:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="popup.aspx.vb" Inherits="popup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lbName" runat=server>
    </asp:Label>
    </div>
    </form>
</body>
</html>
Jens FiedererTest Developer/ValidatorCommented:
popup.aspx.vb:

Partial Class popup
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lbName.Text = Page.Request.Params("id")
    End Sub
End Class
Jens FiedererTest Developer/ValidatorCommented:
If you are using 2003, it is pretty much the same thing, except with a DataGrid instead of a GridView, and of course you just sub in the handler rather than declaring a "Partial Class".

What happens is that you click on the button on one of the rows, and the id is passed to popup.aspx.

In my case I just put the id in a label, but of course you could have multiple fields, and populate them all based on the value of the id.
running32Author Commented:
I get the error schema does not support the element asp:GridView .  Thanks for helping me it would be great to get this example working
Jens FiedererTest Developer/ValidatorCommented:
If you are using 2003, ignore the outer parts such as


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

and use whatever 2003 provides.  Instead of GridView, use DataGrid.
running32Author Commented:
Yes I am using 2003.  I'm trying to change it now.
running32Author Commented:
It will not let me add the button I get the error schema does not support the element button.  Any ideas?  Thanks
Jens FiedererTest Developer/ValidatorCommented:
For 2003 your main aspx should look like this:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="dg.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
   <script type="text/javascript">
    function popit(x) {
        window.open("popup.aspx?id=" + x);
    }
    </script>
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:DataGrid ID="GridView1" runat="server" AutoGenerateColumns="False">
                        <Columns>
                              <asp:BoundColumn DataField="id" />
                              <asp:BoundColumn DataField="name" />
                              <asp:TemplateColumn>
                                    <ItemTemplate>
                                          <button onclick='popit(<%# DataBinder.Eval(Container, "DataItem.id") %>)'>Foo</button>
                                    </ItemTemplate>
                              </asp:TemplateColumn>
                        </Columns>
                  </asp:DataGrid>
            </form>
      </body>
</HTML>
Jens FiedererTest Developer/ValidatorCommented:
with aspx.vb:
Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents GridView1 As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Structure st
        Public m_id As Integer
        Public m_name As String

        Public ReadOnly Property id() As Integer
            Get
                Return m_id
            End Get
        End Property

        Public ReadOnly Property name() As String
            Get
                Return m_name
            End Get
        End Property

    End Structure
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
        Dim l As New ArrayList(4)
        Dim s As New st
        s.m_id = 1
        s.m_name = "a"
        l.Add(s)
        s = New st
        s.m_id = 2
        s.m_name = "b"
        l.Add(s)
        s = New st
        s.m_id = 3
        s.m_name = "ceci"
        l.Add(s)
        s = New st
        s.m_id = 4
        s.m_name = "dada"
        l.Add(s)
        GridView1.DataSource = l
        GridView1.DataBind()
    End Sub


End Class
Jens FiedererTest Developer/ValidatorCommented:
popup.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="popup.aspx.vb" Inherits="dg.popup"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>popup</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">

    <form id="Form1" method="post" runat="server">
    <asp:Label ID="lbName" runat=server>
    </asp:Label>

    </form>

  </body>
</html>
Jens FiedererTest Developer/ValidatorCommented:
popup.aspx.vb:
Public Class popup
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Public lbName As Label
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lbName.Text = Page.Request.Params("id")

    End Sub

End Class
running32Author Commented:
This helped point me in the right direction.  thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.