We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Open a new Window and pass it the variable recordid

running32
running32 asked
on
Medium Priority
2,610 Views
Last Modified: 2008-02-01
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!
Comment
Watch Question

Jens FiedererTest Developer/Validator

Commented:
You can use a regular <button> HTML control, like

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

Test Developer/Validator
Commented:
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")

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
SwapnilSoftware Architect
CERTIFIED EXPERT
Top Expert 2005

Commented:
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


Author

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/Validator

Commented:
What error do you get form the main window?

What is the code in popup.aspx?

Author

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/Validator

Commented:
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/Validator

Commented:
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/Validator

Commented:
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/Validator

Commented:
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/Validator

Commented:
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.

Author

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/Validator

Commented:
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.

Author

Commented:
Yes I am using 2003.  I'm trying to change it now.

Author

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/Validator

Commented:
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/Validator

Commented:
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/Validator

Commented:
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/Validator

Commented:
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

Author

Commented:
This helped point me in the right direction.  thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.