Results 1 to 3 of 3

Thread: [2005] Change NavigateUrl in code?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Between Try & Catch
    Posts
    249

    [2005] Change NavigateUrl in code?

    Hello all.

    Before I begin, this is VB.net code behind.

    Databinding was not my decision. This application was developed by a contractor about a year before I began working here. Now, they want to "expand" the application and because of the databinding behaviors, it's been a bit of a headache.

    Anyway, I have a webpage with a datagrid that is bound to a collection. I have had no problems binding the grid to the proper collection in code.
    However, I have three columns: A, B, C (yea, literally), and each letter is a hyperlink to a different page.

    The problem comes in when I click one of those three column links. The navigate url is hardcoded into the source (because of the databinding? I dunno), so it does not transfer the necessary variables to the next page for proper display. It's still looking for certain values in the grid, which have not been populated by the current collection.

    In short, the navigateurl needs to change based on a session variable.

    Is there any way to change the navigate url in code? If not, is there a way to change it in the source? I am completely out of ideas on this one.
    If my post helped you, please rate it!

    Languages: VB/ASP.NET 2005, C# 2008,VB6
    Databases: Oracle (knowledge not currently in use), DB2

    FROM Customers
    WHERE We_Know_What_We_Want <> DB.Null
    SELECT *
    0 rows returned

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [2005] Change NavigateUrl in code?

    you could register a javascript function in the codebehind to redirect the page for you.

    I'm assuming that navigateurl is just the url the page needs to redirect to.

    Something like this..


    vb Code:
    1. Public Sub redirect(byval url as string)
    2.  
    3. url.Replace("'"," ").Replace('"',' ').Replace('\',' ')
    4. Page.ClientScript.RegisterStartUpScript(typeof(page),"myscript","window.location.href = '"+url+"'",true)
    5.  
    6.  
    7. End Sub

    Hope this is kinda in the direction of your needs,

    Justin Fox

    nevermind me, have no idea what im talkin about
    Last edited by MonkOFox; Jun 3rd, 2008 at 09:39 AM.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

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

    Re: [2005] Change NavigateUrl in code?

    Databinding was not my decision.
    Not sure what you mean by that but if you are indicating a preference towards inline code, then that's "worse".

    In short, the navigateurl needs to change based on a session variable.
    I assume that this then means that the session variable is available when the page is loaded?

    In the grid's OnRowDataBound event, you can handle the rendering of your controls and links. You do this using

    e.Row.FindControl("theID")

    Where "theID" is the ID of the hyperlink control in your grid's templatefield. You said you don't know how the hyperlink is currently being added. Look in the gridview's source in the .aspx file, do you see any TemplateFields? Any hyperlink controls inside those templatefields? If so, then get the ID of the hyperlink control. When you do the FindControl(), it'll find the hyperlink for you.

    Cast it to type Hyperlink (because the FindControl method returns an object) and then set the hyperlink's navigateurl property to whatever you want.

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