[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2585
  • Last Modified:

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!
0
running32
Asked:
running32
  • 13
  • 6
1 Solution
 
Jens FiedererCommented:
You can use a regular <button> HTML control, like

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

0
 
Jens FiedererCommented:
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")
0
 
Swapnil PipariaArchitectCommented:
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


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.
                         
0
 
Jens FiedererCommented:
What error do you get form the main window?

What is the code in popup.aspx?
0
 
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
0
 
Jens FiedererCommented:
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>
0
 
Jens FiedererCommented:
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
0
 
Jens FiedererCommented:
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>
0
 
Jens FiedererCommented:
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
0
 
Jens FiedererCommented:
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.
0
 
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
0
 
Jens FiedererCommented:
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.
0
 
running32Author Commented:
Yes I am using 2003.  I'm trying to change it now.
0
 
running32Author Commented:
It will not let me add the button I get the error schema does not support the element button.  Any ideas?  Thanks
0
 
Jens FiedererCommented:
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>
0
 
Jens FiedererCommented:
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
0
 
Jens FiedererCommented:
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>
0
 
Jens FiedererCommented:
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
0
 
running32Author Commented:
This helped point me in the right direction.  thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 13
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now