How can I assign NavigateURL to hyperlink from Session variable in html sorce code?

avacaralife
avacaralife used Ask the Experts™
on
Hi,
I want to assign gavigate URL from session variable like:<asp:HyperLink ID="hlHome"  NavigateUrl='<%= (Session["link"]) %>' runat="server">Home</asp:HyperLink>

This is not working. So how can I do this?

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I've battled with this too, and the only way I could get it to work was from my code...
In Page_Load I put:
hlHome.NavigateUrl = Session("link")
Espavo

Author

Commented:
No no dear I required at design time. Can u help?
Thanks..

Commented:
The correct format for this sort of thing is:
<asp:HyperLink ID="hlHome" NavigateUrl='<%= Session("link") %>' runat="server">Home</asp:HyperLink>
What does that do at run-time?
Espavo

Author

Commented:
Dear Espavo,
thanks for your reply.
I am doing to change nevigate url at run time which is taken from session variable 'link'. I do not want to write code.
thanks

Commented:
So, I just tried what I posted earlier and it didn't work...
What did work, however was this:
<a href='<%= Session("link") %>'>Home</a>
Espavo

Author

Commented:
Yes Espavo,
This is working with html control. But its not working with asp.net control like Hyperlink.

Nilesh

Commented:
That has been my experience too... whenever RunAt="Server" is specified then it doesn't work...
The two ways that I've found that do work are above:
  1. Passing the value from Code
  2. Using an HTML control instead of a ASP control
Espavo

Author

Commented:
OK thanks ESPAVO
Catch u later...!
Amit TripathiSharePoint Architect

Commented:
Its Simple just Make one Function at Server Side like Below one.

 public  string RtSession()
    {
        return Session["URl"];
    }

And call
it like Below..

<asp:HyperLink ID="hyp" runat="server" NavigateUrl="<%# RtSession() %>" >amit</asp:HyperLink>

It's Work 100%%%%%.......

Regards,
Amit Tripathi

Author

Commented:
Thanks amittripathi,

I have try your solution but does not work.

Nilesh
Thanks
Now temparary I accept the solution for it. I will post it later..

Author

Commented:
No objection here.

Author

Commented:
I need to enter another question, So I need to remove this question. So I temparary accept the solution.
So I have select no as above option.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial