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 / September 2007

Tip: Looking for answers? Try searching our database.

Binding Hyperlink.NavigateUrl declaratively

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dmitry Duginov - 13 Sep 2007 23:21 GMT
I have a FormView and a HyperLink on the page.

If I use the following code behind (hooked up to Hyperlink's OnLoad event),
it renders fine

   protected void link_Load(object sender, EventArgs e)
   {
       link.NavigateUrl = String.Format("~/Carrier/AddNew.aspx?Id={0}",
FormView1.DataKey.Value);
   }

However, I was not able to achieve the same goal declaratively, just using
<%# ... %> syntax in .aspx

Where's the catch?

Dmitry
densial - 13 Sep 2007 23:44 GMT
> I have a FormView and a HyperLink on the page.
>
[quoted text clipped - 13 lines]
>
> Dmitry

show us your code for the second one
Dmitry Duginov - 14 Sep 2007 00:52 GMT
>> I have a FormView and a HyperLink on the page.
>>
[quoted text clipped - 17 lines]
>
> show us your code for the second one

Any of the following renders just text instead of hyperlink:
NavigateUrl='<%# String.Format("~/Carrier/AddNew.aspx?Id={0}",
Eval("FormView1.DataKey.Value")) %>'

NavigateUrl='<%# String.Format("~/Carrier/AddNew.aspx?Id={0}",111) %>'

NavigateUrl='<%# Eval("FormView1.DataKey.Value") %>'

D.
Walter Wang [MSFT] - 14 Sep 2007 04:24 GMT
Hi Dmitry,

I've done some test and both of following approaches should work for you:

<asp:HyperLink ID="link1" runat="server" Text="Link" NavigateUrl='<%#
String.Format("~/Carrier/AddNew.aspx?id={0}", Eval("Id"))
%>'></asp:HyperLink>
<br />
<asp:HyperLink ID="link2" runat="server" Text="Link2" NavigateUrl='<%#
String.Format("~/Carrier/AddNew.aspx?id={0}", FormView1.DataKey.Value)
%>'></asp:HyperLink>

The first one is assuming you need to use some field as the id; the second
one is the exact case as yours.

Please feel free to let me know if there's anything I can help.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Dmitry Duginov - 14 Sep 2007 15:00 GMT
> Hi Dmitry,
>
[quoted text clipped - 4 lines]
> %>'></asp:HyperLink>
> <br />

First one doesn't woudn't since I dont have Id control

> <asp:HyperLink ID="link2" runat="server" Text="Link2" NavigateUrl='<%#
> String.Format("~/Carrier/AddNew.aspx?id={0}", FormView1.DataKey.Value)
> %>'></asp:HyperLink>

Second one "just" doesn't work. It renders text only:
<a id="ctl00_ContentPlaceHolder1_link2">Link2</a>

D.

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.