Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Datagrig window.open registerstartupscript problem

Posted on 2005-04-06
6
Medium Priority
?
357 Views
Last Modified: 2008-02-01
Hi All. I have just finished a contract and returned to a project I was working on. Something very odd has happened while I was away. I have a DataGrid which dispayes a set of results from our DB. The datagrid has a button called "Play". When "Play" is clicked, it should bring up a poup window displaying a "Music Player". This code below worked 3 weeks ago but is not working now. I already tried RegisterClientScriptBlock. Any bright ideas on what is happening? In advance, many thanks for all your help.

This is a stripped down version of the code:

VB.NET
####################
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        Dim i As Integer
        Dim dr As DataRow
        dt.Columns.Add("SomeCol", System.Type.GetType("System.String"))
        For i = 1 To 4
            dr = dt.NewRow()
            dr("SomeCol") = i.ToString
            dt.Rows.Add(dr)
        Next
        DataGrid1.DataSource = dt
        DataGrid1.DataBind()
    End Sub

    Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
        If e.CommandName = "Play" Then
            Dim popupScript As String = "<script language='javascript'>" & _
            "window.open('../player/right_frame.aspx', 'Window', 'width=200, height=200');" & _
            "</script>"

            Page.RegisterStartupScript("playerPopup", popupScript)

        End If
    End Sub

###########################

HTML

##########################

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="tests_to_be_deleted_popups.aspx.vb" Inherits="bubblewap.net.tests_to_be_deleted_popups"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>tests_to_be_deleted_popups</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <script language="javascript">
      </HEAD>
      <body onload="getPopping()" MS_POSITIONING="GridLayout">
      <form id="Form1" method="post" runat="server">
      <asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 40px; POSITION: absolute; TOP: 272px" runat="server">Label</asp:Label>
      <asp:DataGrid id="DataGrid1" style="Z-INDEX: 105; LEFT: 24px; POSITION: absolute; TOP: 64px" runat="server"
      BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4">
      <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
            <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
            <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
            <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
            <Columns>
            <asp:ButtonColumn Text="Play" CommandName="Play"></asp:ButtonColumn>
            </Columns>
            <PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
            </asp:DataGrid>
                 </form>
      </body>
</HTML>

###########################
0
Comment
Question by:Phillie
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 200 total points
ID: 13716034
try using Template column instead of a button column:


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="tests_to_be_deleted_popups.aspx.vb" Inherits="bubblewap.net.tests_to_be_deleted_popups"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
     <HEAD>
          <title>tests_to_be_deleted_popups</title>
          <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
          <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
          <meta content="JavaScript" name="vs_defaultClientScript">
          <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
          <script language="javascript">
     </HEAD>
     <body onload="getPopping()" MS_POSITIONING="GridLayout">
     <form id="Form1" method="post" runat="server">
     <asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 40px; POSITION: absolute; TOP: 272px" runat="server">Label</asp:Label>
    <asp:datagrid id="DataGrid1" style="Z-INDEX: 105; LEFT: 24px; POSITION: absolute; TOP: 64px" runat="server"
                                                CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966">
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
                                                <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
                                                <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
                                                <Columns>
                                                      <asp:TemplateColumn>
                                                            <Itemtemplate>
                                                                  <asp:Button ID="btnPlay" Runat="server" Text="Play"></asp:Button>
                                                            </Itemtemplate>
                                                      </asp:TemplateColumn>
                                                </Columns>
                                                <PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
                                          </asp:datagrid>
                 </form>
     </body>
</HTML>


and then add the following code to Page_load event:

btnPlay.Attributes.Add("onclick", "javascript:window.open('../player/right_frame.aspx', 'Window', 'width=200, height=200');")
0
 

Author Comment

by:Phillie
ID: 13716963
hi YZlat. thanks. each of the "Play" buttons is dynamic and carries a queryString with it i.e page.aspx?userID=XXXtrackID=XXX..... so it not a question of just one button. there are quite a few of them. these are generated by the fields in the datagrid i.e datagrid1.items(x).Cells(x) and repeats itself for all the retuned entries. i am not sure if btnPlay.Attributes.Add can be made dynamic in this case? any thoughts?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 13720095
Phillie the code above will produce as many buttons as there are rows in the datagrid. You could also change it to a link ro a linkbutton and pass it a unique query string
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question