|
-
Jun 3rd, 2008, 09:23 AM
#1
Thread Starter
Addicted Member
[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
-
Jun 3rd, 2008, 09:35 AM
#2
Frenzied Member
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:
Public Sub redirect(byval url as string)
url.Replace("'"," ").Replace('"',' ').Replace('\',' ')
Page.ClientScript.RegisterStartUpScript(typeof(page),"myscript","window.location.href = '"+url+"'",true)
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.
-
Jun 3rd, 2008, 03:07 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|