473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Binding Hyperlink.NavigateUrl declaratively

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
Sep 13 '07 #1
6 23497
On Sep 14, 10:21 am, "Dmitry Duginov" <d...@nospam.nospamwrote:
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
show us your code for the second one

Sep 13 '07 #2

"densial" <de*****@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
On Sep 14, 10:21 am, "Dmitry Duginov" <d...@nospam.nospamwrote:
>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

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.
Sep 13 '07 #3
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 (wa****@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.
Sep 14 '07 #4

""Walter Wang [MSFT]"" <wa****@online.microsoft.comwrote in message
news:bm**************@TK2MSFTNGHUB02.phx.gbl...
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 />
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.
Sep 14 '07 #5

""Walter Wang [MSFT]"" <wa****@online.microsoft.comwrote in message
news:g8******************@TK2MSFTNGHUB02.phx.gbl.. .
Hi Dmitry,

First one is just an example, just to describe an approach if you need to
use some filed instead of the DataKey.

Are you using a multi fields DataKey? Would you please post your complete
code or send me a complete project?
Nope, it is single-field DataKey. The significant difference between your
code and mine is that my link is outside the FormView (see a new line for
link3). This way is doesn't work.

<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>
</ItemTemplate>
</asp:FormView>
<asp:HyperLink ID="link3" runat="server" Text="Link3"
NavigateUrl='<%# String.Format("~/Carrier/AddNew.aspx?id={0}",
FormView1.DataKey.Value) %>'></asp:HyperLink>

Dmitry
Sep 17 '07 #6
Hi Dmitry,

I'm writing to check the status of this post. Please feel free to let me
know if there's anything else I can help. Thanks.

Regards,
Walter Wang (wa****@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.

Sep 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Boban Dragojlovic | last post by:
in the codebehind portion of a page, I dynamically create a series of hyperlinks that I add to the page. in that code, I have something like this: dim h as new hyperlink h.NavigateURL =...
5
by: Mark Fox | last post by:
Hello, When I set a hyperlink server control's NavigateUrl to Webform.aspx?a=0&b=0 it outputs Webform.aspx?a=0&amp;b=0
0
by: Cynic07 | last post by:
As you can guess it in my subject, my question is for Microsoft System.Web.UI.WebControls team: Why HyperLink.NavigateUrl property is not marked as virtual? (I cannot override this property in...
0
by: Nathan Sokalski | last post by:
Whenever I assign a value to the HyperLink.NavigateUrl property, it adds an extra ../ in the generated href= attribute of the anchor tag. For example, when I assign it the value "comments.aspx" the...
2
by: gerry | last post by:
I have a page that has an asp:Hyperlink control on it. The NavigateUrl is set to "~/Aaa/Bbb.aspx" When the link is rendered it is rendered as Aaa/Bbb.aspx which I would think is completely...
0
by: David W | last post by:
I would like to be able to evaluate an expression in the NavigateUrl property of a HyperLink control. This is not a bound control. I know I can do this easily in code-behind, but do not want to...
6
by: Jason Huang | last post by:
Hi, In my ASPNet 2.0 C# web form, there's a <asp:HyperLink ID="HyperLinkA" ... NavigateUrl="http://MyIP/MyFolder/MySubFolder"TestLink </asp:HyperLink> My question is how to config the...
1
by: Jason Huang | last post by:
Hi, My ASPNet HyperLink NavigateUrl is like http://192.168.0.1/OtherFolder/§ÚªºÀɮק¨/myfile, the OtherFolder is another folder rather than the ASPNet application's default folder in the IIS....
4
by: W4yne | last post by:
I have a datalist with the following <asp:HyperLink ID="link1" runat="server" Text='<%# Eval ("Name_of_rally") %>' NavigateUrl='<%# String.Format("somePages.aspx?id={0}", Eval("id")) %>'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.