473,799 Members | 3,082 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 23523
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
959
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
3447
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
1312
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
6483
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
2328
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
9546
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
10490
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
9078
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...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
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.