Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

NavigateURL/DataNavigateURLFormatString and Session Variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 03 Aug 2007 23:51 GMT
I gave up on the Page.ResolveURL and just got the Current Path from the
Request.ServerVariables("Path_Info") and put it in a session variable.  I
thought I could use a session variable to pass the path in since the other
won't work.  But I am getting the same type of error.

        <asp:HyperLinkColumn ItemStyle-Width="190" DataTextField="JobTitle"
         DataTextFormatString="{0}" DataNavigateUrlField="PositionID"
         DataNavigateUrlFormatString='<%= session("PagePath")
%>displayPositionNS.aspx?PositionID={0}'
         headertext="Job Title"
         ItemStyle-VerticalAlign="Top"
         sortexpression="JobTitle"/>

session("PagePath") = /JobSeeker/

The link in the DataGrid:

http://www.stw.com/applicant/<%=%20session("PagePath")%20%>displayPositionNS.asp
x?PositionID=442


Not only won't it use the session variable - it still uses the Controls path
(/applicant/) and not the Path I tell it to use.

I also tried it with the <%# %> with the same result.

Is there anyway to use a session variable with the Hyperlink???

Thanks,

Tom
Milosz Skalecki [MCAD] - 04 Aug 2007 00:10 GMT
Hi there,

First, you cannot use <%=%> for server controls, the only allowed are data
bound <%# %> (in conjunction with a DataBind() method call) and resource <%$
%> expressions. Second, use ~ (tilde) in the URL as it is resolved
automatically by all the controls (by calling ResolveUrl method):

<asp:HyperLinkColumn
    ItemStyle-Width="190" DataTextField="JobTitle"
    DataTextFormatString="{0}"
    DataNavigateUrlField="PositionID"
    DataNavigateUrlFormatString="~/displayPositionNS.aspx?PositionID={0}"
    HeaderText="Job Title"
    ItemStyle-VerticalAlign="Top"
    SortExpression="JobTitle"/>

hope this helps
Signature

Milosz

> I gave up on the Page.ResolveURL and just got the Current Path from the
> Request.ServerVariables("Path_Info") and put it in a session variable.  I
[quoted text clipped - 25 lines]
>
>  Tom
tshad - 06 Aug 2007 17:41 GMT
> Hi there,
>
[quoted text clipped - 3 lines]
> %> expressions. Second, use ~ (tilde) in the URL as it is resolved
> automatically by all the controls (by calling ResolveUrl method):

Actually, that is not the case.  Apparently, it doesn't call the ResolveURL
(which sends back the Current Page URL).  No matter how you do it, it comes
back with the Controls' URL.  Which means if you do it the normal way, you
absolutely cannot call it from different folders.  If  you call it this way,
you will get the path of the control.

For example:

If you have

http://www.stw.com/jobseeker/displayCompanyJobs.aspx  and
/applicant/displayCompanyJobs.ascx                       (my control loaded
into displayCompanyJobs.aspx)

Where displayCompanyJobs trys to load displayCompanyOverview.aspx - It will
use the path of the Control (www.stw.com/applicant/ and not
www.stw.com/jobSeeker as you would expect and is done by every other
Redirect object or tag)

The ~ really doesn't do anything, as far as I can tell.  Here is what will
happen for different ways of calling displayCompanyOverview.

<asp:Hyperlink Text="with ~/ " NavigateUrl="~/displayCompanyOverview.aspx"
runat="server"/><br>

http://www.stw.com/displayCompanyOverview.aspx     (where is the applicant
or jobseeker folder????)

<asp:Hyperlink Text="with ~/ and jobseeker "
NavigateUrl="~/jobseeker/displayCompanyOverview.aspx" runat="server"/><br>

http://www.stw.com/JobSeeker/displayCompanyOverview.aspx    (Current Page
Path but worthless as it is called from the control and not the page)

<asp:Hyperlink Text="with / " NavigateUrl="/displayCompanyOverview.aspx"
runat="server"/><br>

http://www.stw.com/displayCompanyOverview.aspx

<asp:Hyperlink Text="with no tilde or / "
NavigateUrl="displayCompanyOverview.aspx" runat="server"/><br>

http://www.stw.com/applicant/displayCompanyOverview.aspx        (Controls
Path)

If you call ResolveURL as so:
 test = Page.ResolveUrl("displayCompanyOverview.aspx")
 trace.warn("ResolveURL = " & test)

You will get in the trace:

ResolveURL = /JobSeeker/displayCompanyOverview.aspx

As you see ResolveURL gives you the Current Page Path.

You cannot use Page.ResolveURL in your HyperLink, however.  It doesn't
resolve it.  And you cannot use ResolveClientURL in .Net 1.1.  You get the
error - " not accessible in this context because it is 'Private'"

I also tried to put the path in a session variable and found I couldn't get
the inline call to get the session variable.

These are things you can't do.  Here is what you can do and it works well.

I have and found a very good solution - similar to your approach.  I am
using the OnPreRender event - which gives me the line that needs to be
handled and I don't have to check to see if the object is a correct type of
object.
Works great.

Here is what I did - for anyone in the same situation.

The ServerVariables("PATH_INFO") in my situation gives me:
/JobSeeker/displayCompanyJobs.aspx  So I just take out the
displayCompanyJobs.aspx and I have the Current pages path.  As the session
variables - as far as I could tell, you cannot use this
ServerVariables("PATH_INFO") in the Hyperlink object.

The event I created was:

Sub FixHyperLink(s as Object, e as EventArgs)
 s.NavigateURL =
request.ServerVariables("PATH_INFO").Substring(0,request.ServerVariables("PATH_INFO").LastIndexOf("/")+1)
& s.NavigateURL
end Sub

Then for all my Hyperlinks I add:

OnPreRender="FixHyperLink"

Now my Hyperlink looks like:

<asp:hyperlink text='<%# Container.DataItem("JobTitle")%>' NavigateUrl='<%#
"displayPositionNew.aspx?PositionID=" & Container.DataItem("PositionID") %>'
OnPreRender="FixHyperLink" runat="server" />

I also changed my HyperLinkColumns to:

   <asp:TemplateColumn sortexpression="JobTitle" ItemStyle-Width="250px"
HeaderStyle-Width="250px"
            headertext="Job Title" ItemStyle-VerticalAlign="Top"
runat="server">
       <ItemTemplate>
            <asp:HyperLink ID="JobTitle"
             NavigateURL='<%# "displayPositionNew.aspx?PositionID=" &
Container.DataItem("PositionID") %>'
             Text='<%# Container.DataItem("JobTitleDesc")%>'
             OnPreRender="FixHyperLink"
             runat="server"/>
      </ItemTemplate>
   </asp:TemplateColumn>

There is no event on HyperLinkColumns and the problem with ItemDataBound and
RowDataBound is that you need to check all the controls in the rows to find
any HyperLinkColumn type fields then make the change.

Thanks,

Tom

> <asp:HyperLinkColumn
> ItemStyle-Width="190" DataTextField="JobTitle"
[quoted text clipped - 39 lines]
>>
>>  Tom

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.