Results 1 to 31 of 31

Thread: [RESOLVED] Want GridView Hyperlink to open window

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Resolved [RESOLVED] Want GridView Hyperlink to open window

    I've been hacking and googling for a while now, I guess it's time to ask the experts.

    I have a link in my gridview that when clicked should open a popup window. I want scrollbars, a menubar and it should be sizable. So this is what I have. It is not working. You click the link and nothing happens.

    Code:
                    <asp:TemplateField HeaderText="Est. Total">
                        <ItemTemplate>
                        <asp:HyperLink 
                                 ID="hyEstTotal" runat="server" 
                                 Text='<%# String.Format("{0:c}", Eval("total")) %>'
                                 >
                        </asp:HyperLink>
                        </ItemTemplate>
                   </asp:TemplateField>
    And the code-behind:
    Code:
                    Dim hyEstTotal As HyperLink = DirectCast(Me.GridView1.Rows(idxGrid).FindControl("hyEstTotal"), HyperLink)
    
                    hyEstTotal.NavigateUrl = _
                        "javascript:popUp('show_estimate.aspx?ID=" + CStr(ds.Tables(0).Rows(idxData).Item("invoice_id")) + "', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');"
    The link looks fine, it is being generated exactly as it should, it just doesn't...link.

    Thanks.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    I lied.

    I had so many darn IE windows open that I didn't see that my popup window was opening.

    However, the main thing I am trying to accomplish is to get the scrollbars and I do not have them. It is sizable and I have the menubar but I don't have scrollbars. My grid is overlapping off the window and I have to maximize to see it but that's still not all of it.

    What am I doing wrong?

  3. #3
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Want GridView Hyperlink to open window

    Try using windows.open method in that u can specify the features of the pop-up page like

    Code:
    "'width=750,height=500,left=100,top=80,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes'"

  4. #4

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Thank you for the reply. I thought I was doing that. Did you scroll my code all the way over to the right? I'm not sure what you're suggesting that's different from what I am already doing. Thanks.

  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Want GridView Hyperlink to open window

    Is popUp() in your code a JS function?
    Show Appreciation. Rate Posts.

  6. #6
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Want GridView Hyperlink to open window

    hmmm i overlook that

    btw just give it a try with windows.open, as mentioned above even i am not aware about popup()

    window.open('" & sUrl & "',''," & sFeatures & ");
    Last edited by riteshjain1982; May 14th, 2008 at 09:39 AM.

  7. #7

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Harsh and riteshjain1982:

    popUp was in my javascript. I did as riteshjain1982suggested and am using open.window instead. It works but there's still no scrollbars. Plus this odd behavior: On the page where I clicked in the gridview, that page loses all its contents and displays the word [object] instead. That's it for the whole page. (I believe this was happeninig with popUp also).

    I hope this isn't another weird problem I'm so good at getting myself into...

    Thanks.

  8. #8
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Want GridView Hyperlink to open window

    Does clicking on the link causing the page to postback.

    Are you setting the NavigateURL property in onRowDataBound event? I guess, you are not. I think you are setting this property in Page Load event wrapped inside IsPostBack check.

    I might be wrong though!!!
    Show Appreciation. Rate Posts.

  9. #9

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    You are right: I am not setting it in RowDataBound.

    You are wrong: I am not setting it in PageLoad.

    I hope you are not sorry you asked: I have filters on my page where the user can say what kind of records he wants to see in the grid. So let's say he says he wants to see all records with a customer name like "truck". He fills that info out then hits a submit button. Here's my code from then on:
    Code:
        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    
            PopulateGrid()
    
        End Sub
    
        Sub PopulateGrid()
    
            Dim ds As New DataSet
    
            GetDataForGrid(ds)   ' Gets data according to filters user selected
    
            Me.GridView1.DataSource = ds
    
            Try
                Me.GridView1.DataBind()
    
    
                ' Row-by-row of the grid, process each column...
                Dim idxData As Integer
                Dim idxGrid As Integer = 0
                For idxData = Me.GridView1.PageSize * Me.GridView1.PageIndex _
                  To Me.GridView1.PageSize * (Me.GridView1.PageIndex + 1) - 1
    
                    Dim hyEstTotal As HyperLink = DirectCast(Me.GridView1.Rows(idxGrid).FindControl("hyEstTotal"), HyperLink)
    
                    hyEstTotal.NavigateUrl = _
                        "javascript:window.open('show_details.aspx?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik")) + "', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');"
    
                    If idxData >= (ds.Tables(0).Rows.Count - 1) Then Exit For
    
                    idxGrid += 1
    
                Next
    Do you see something that's incorrect?

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    vb Code:
    1. hyEstTotal.Attributes.Add("onclick", _
    2.                     "javascript:window.open('show_details.aspx?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik")) + "', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');return false;")
    3.  
    4. hyEstTotal.NavigateUrl = "javascript:void;"
    5. 'Or
    6. 'hyEstTotal.NavigateUrl = "show_details.aspx?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik"))

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    The reason you get the [object] displayed is when you click on the link, the page is attempting to 'go to' what the href is telling it to go to. The href is calling some javascript. window.open() returns a value that is a javascript "object". Browser sees that and displays it.

  12. #12

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Thank you. [object] has gone away! But, I *still* don't have scrollbars. I really want these scrollbars, otherwise I wouldn't be such a pain!

  13. #13

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    I know computers can be flaky, but can you get anymore clear than this: scrollbars=1!!!!

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    The only assumption I can make is that this has something to do with browser settings. Try this in another browser. Try setting a smaller height and width. Try a temporary URL like vbforums.com or mendhak.com

  15. #15

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Thanks for the suggestions. I was also thinking of trying the same code with another of my pages that I want to open in the same manner. Will let you know how it turns out...

  16. #16

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    No matter what I do, I can't scroll.

    The only one of mendhak's suggestions I couldn't try, was to code a url such as www.vbforums.com in my link because my code looked for it inside its own folder structure. None of the other suggestion revealed anything (Firefox, surprisingly, was worse and even the parts of the non-scrollable window that worked in IE7 didn't work in Firefox).

    This page is in production so I really need it to scroll. I don't know what else to try.

    Help, please. I'm so stuck.

  17. #17

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    IE6 won't work either. At least it's a consistent problem.

    My coworker just offered me some nuts from his bag of almonds. I said I needed a bag of scrollbars...

    Anyone got any???

    I guess I should post my lastest and not-so-greatest code:
    Code:
                    Dim hyEstTotal As HyperLink = DirectCast(Me.gvUploadRateReady.Rows(idxGrid).FindControl("hyEstTotal"), HyperLink)
                    'hyEstTotal.Attributes.Add("onclick", _
                    '  "javascript:window.open(ThisPageWontScroll.aspx?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik")) + "', 'DETAILS', 'scrollbars=1');")
                    hyEstTotal.Attributes.Add("onclick", _
                      "javascript:window.open(ThisPageWontScroll.aspx?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik")) + "', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');return false;")
                    'hyEstTotal.Attributes.Add("onclick", _
                    '  "javascript:window.open('www.vbforums.com', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');return false;")
                    hyEstTotal.NavigateUrl = "javascript:void;"

  18. #18

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Quote Originally Posted by MMock
    The only one of mendhak's suggestions I couldn't try, was to code a url such as www.vbforums.com in my link
    I needed http:// in front, oops.

    Eureka! vbforums opens with scroll bars! So it must be in my page, not how I am opening it??? Thanks for the trouble-shooting tip, mendhak!

  19. #19

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    I substituted the old asp page for my new aspx page and it is opening with scrollbars. I am certain now it is in the page I am going to...I just have to find out why.

  20. #20
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    When you do your window.open, you're not giving a single quote to the page name.

    vb Code:
    1. Dim hyl As New HyperLink()
    2.             hyl = CType(e.Row.FindControl("hyl"), HyperLink)
    3.             hyl.Attributes.Add("onclick", _
    4.                   "window.open('http://www.mendhak.com/', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');return false;")
    5.             hyl.NavigateUrl = "#"
    6.             hyl.Text = "lol"

  21. #21

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Do I really have to put everything in a panel?

  22. #22

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    Quote Originally Posted by mendhak
    When you do your window.open, you're not giving a single quote to the page name.
    I'm sorry - I think we cross-posted there. To which of my rapid-fire-in-succession posts was this an answer???

  23. #23
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    I answered #17. I tried my code out and it worked - I got a popup window and the scrollbar, etc.

    What I noticed missing for you was that single quote.

  24. #24

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    In an effort to protect my company's secrets I edited the instruction and I think I deleted the single quote and misled you. So this is the truth, the whole truth, blah blah blah:

    Code:
                    hyEstTotal.Attributes.Add("onclick", _
                      "javascript:window.open('show_inv_details_estimate.asp?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik")) + "', 'DETAILS', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600');return false;")
                    'hyEstTotal.Attributes.Add("onclick", _
                    '  "javascript:window.open('show_inv_details_estimate.aspx?inv_hdr_ik=" + CStr(ds.Tables(0).Rows(idxData).Item("inv_hdr_ik")) + "', 'DETAILS', 'scrollbars,menubar,resizable,width=800,height=600');return false;")
    I promise you, the first one has scroll bars. When I comment out the first way and try the second, there are no scroll bars. It must be show_inv_details_estimate.aspx. It is full of gridviews and they are off the bottom of the page. Do I have to put them all in a panel?

    Thanks, and I apologize for my mistake.

  25. #25
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    The first one has

    'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,location=0,width=800,height=600 '

    The second one has

    'scrollbars,menubar,resizable,width=800,height=600'



    Did that make a difference?

  26. #26

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    When I was googling, I saw sample code that instead of saying =1 or =0 just said the name of what they wanted and if it was zero left the name off, know what I mean? So to get scrollbars it was just "scrollbars" and if they didn't want scrollbars they just left that keyword out. It was something I tried that made no difference.

    Are you making whatever attempt you can on my behalf so I don't have to redesign the page with a panel? Or you don't think panels are what I need?

    Thanks.

  27. #27
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    Alright, so you get a popup... and for the ASPX version it won't show a scrollbar.

    First question - when you view that ASPX normally, in a normal tab (not a popup, does it show the scrollbars?

    Second, what does the markup look like on this offending page?

    Not sure what you mean by panels here but you should be able to get this sorted by modifying the markup in the offending page to allow for scrollbars.

  28. #28

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window

    I've *never* seen scrollbars on this page.

    Markup (hope you're not sorry you asked...it's long, hence the need for scrollbars!): Oops - it made my post exceed the mask. I've attached it.

    Regarding panels...when I googled asp.net and scrollbars, the first few hits all said something about putting your controls on a panel and scrolling the panel.

    Thanks.
    Attached Files Attached Files

  29. #29
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Want GridView Hyperlink to open window

    Took me 0.5 seconds to find it.

    html {
    overflow: hidden;
    }

    That means that if there's an overflow, don't show it. Keep it hidden from the user.

  30. #30

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Want GridView Hyperlink to open window



    Quote Originally Posted by mendhak
    Took me 0.5 seconds to find it.
    If I were you, I wouldn't have posted until Monday and told me you worked on it all weekend long! You could've given me an asp file back and told me to replace mine, and I don't think I ever would've noticed the one-line change! But I wouldn't have learned anything either.

    If I weren't so happy I'd feel very stupid. Thanks. My appreciation is in no way proportionate to how long it took you to find it (well, I'm not forgetting there were like 28 posts in this thread that you read through!)

  31. #31
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Want GridView Hyperlink to open window

    Hehe... and to think that all the previous discussion was moot, due to this one tiny CSS setting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width