473,811 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding Hyperlink.Navig ateUrl 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(objec t sender, EventArgs e)
{
link.NavigateUr l = String.Format(" ~/Carrier/AddNew.aspx?Id= {0}",
FormView1.DataK ey.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 23524
On Sep 14, 10:21 am, "Dmitry Duginov" <d...@nospam.no spamwrote:
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(objec t sender, EventArgs e)
{
link.NavigateUr l = String.Format(" ~/Carrier/AddNew.aspx?Id= {0}",
FormView1.DataK ey.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******** *************@5 0g2000hsm.googl egroups.com...
On Sep 14, 10:21 am, "Dmitry Duginov" <d...@nospam.no spamwrote:
>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(objec t sender, EventArgs e)
{
link.NavigateUr l = String.Format(" ~/Carrier/AddNew.aspx?Id= {0}",
FormView1.Data Key.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:HyperLin k ID="link1" runat="server" Text="Link" NavigateUrl='<% #
String.Format(" ~/Carrier/AddNew.aspx?id= {0}", Eval("Id"))
%>'></asp:HyperLink>
<br />
<asp:HyperLin k ID="link2" runat="server" Text="Link2" NavigateUrl='<% #
String.Format(" ~/Carrier/AddNew.aspx?id= {0}", FormView1.DataK ey.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.comwr ote in message
news:bm******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Dmitry,

I've done some test and both of following approaches should work for you:
<asp:HyperLin k 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:HyperLin k ID="link2" runat="server" Text="Link2" NavigateUrl='<% #
String.Format(" ~/Carrier/AddNew.aspx?id= {0}", FormView1.DataK ey.Value)
%>'></asp:HyperLink>
Second one "just" doesn't work. It renders text only:
<a id="ctl00_Conte ntPlaceHolder1_ link2">Link2</a>

D.
Sep 14 '07 #5

""Walter Wang [MSFT]"" <wa****@online. microsoft.comwr ote in message
news:g8******** **********@TK2M SFTNGHUB02.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:HyperLin k ID="link1" runat="server" Text="Link"
NavigateUrl='<% # String.Format(" ~/Carrier/AddNew.aspx?id= {0}", Eval("Id"))
%>'></asp:HyperLink>
<br />
<asp:HyperLin k ID="link2" runat="server" Text="Link2"
NavigateUrl='<% # String.Format(" ~/Carrier/AddNew.aspx?id= {0}",
FormView1.DataK ey.Value) %>'></asp:HyperLink>
</ItemTemplate>
</asp:FormView>
<asp:HyperLin k ID="link3" runat="server" Text="Link3"
NavigateUrl='<% # String.Format(" ~/Carrier/AddNew.aspx?id= {0}",
FormView1.DataK ey.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
1933
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 = "/somepage.aspx?age=35&gender=M"
5
3970
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
960
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 a derived HyperLink control). Thanks!
0
1291
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 href attribute comes out as href="../comments.aspx" The location of the file with the code that generates the anchor is in the root directory, while the aspx file is one level deeper. Could this be the problem? If it is, how can I fix it so that...
2
3448
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 incorrect. As I understand the use of the this syntax , ~ should be replaced by the application path. so for an application in the root this value should be /Aaa/Bbb.aspx for an application in the /Ccc/Ddd directory this should be...
0
1313
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 do it that way - I want to be able to drop the link on any page. <asp:HyperLink ID="hlHomePage" runat="server" NavigateUrl='<%# Session("HomePath") & "home.aspx" %>' Text="Home"></asp:HyperLink> The above does not evaluate and produces a link...
6
6484
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 NavigateUrl as the combination of 2 strings "MyIPString"+"MyFolderString"? Thanks for help.
1
1538
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. However, since there're some none English characters in the NavigateUrl, the characters after the OtherFolder/ becomes some "%e6%b8%ac%e8%a9%a6%e5%a0%b1%", and the Link is not functionning properly. Would someone give me some advice? Thanks for...
4
2329
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")) %>' Font-Bold="True" Font-Size="Large"> </asp:HyperLink> This opens a new page with the URL somepages.aspx?id=7 how do I use this id number
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.