Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2009, 02:47 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default A href issue

Hi People. I am currently facing a problem to allow a href on a Databind item. For example, The TextInput stated below will retrieve all the links posted by a user. For instance, if a user posted www.youtube.com or www.p2p.wrox.com , it will allow them to click on the Label and proceed to the link in a new window. Could someone advise me how to work on it?

Codes

<
ahref=""><asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label></a><br/><br/>
 
Old March 23rd, 2009, 04:54 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

I dont know much about asp.net, but I am giving you general syntax

<a href="<%# Bind("TextInput") %>" target="_blank" > <asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label></a><br/><br/>


__________________
urt

Help yourself by helping someone.
 
Old March 23rd, 2009, 05:13 AM
Registered User
 
Join Date: Sep 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hi.huangls
Default

maybe the up's answer doesn't work,
you can do like this./

<a href="<%# Bind("TextInput") %>" target="_blank" > <asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label></a><br/><br/>

<a target='_blank' href='<%#Eval("
TextInput")%>'>
<
asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput")%>'/>
</a>
 
Old March 23rd, 2009, 05:24 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

hahaa. thanks for the help guys. But it doesnt work.
It stated
A call to Bind must be assigned to a property of a control inside a template.
What does it mean
 
Old April 20th, 2009, 04:32 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

In this example I have a SQLSource on my page with a field called MenuDescription and want to call a link defined in a field called MenuPageName with an optional Parameter defined in a field called MenuPageID.

On the .aspx page I have (in a datagrid template field) the following code


<ItemTemplate>
<tablestyle="width: 100%">
<tr>
<tdstyle="width: 20px">
</td>
<td>
<asp:Hyperlinkrunat="server"Text='<%# DataBinder.Eval(Container.DataItem,"MenuDescriptio n").tostring%>'NavigateUrl='<%# DataBinder.Eval (Container.DataItem,"MenuPageName").tostring & ".aspx?ID=" & DataBinder.Eval (Container.DataItem,"MenuPageID").tostring %>'ID="Menu"/>
</td>
</tr>
</table>
<br/>
</ItemTemplate>


Hope this helps

Tim

 
Old April 21st, 2009, 03:38 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
Originally Posted by julius View Post
Hi People. I am currently facing a problem to allow a href on a Databind item. For example, The TextInput stated below will retrieve all the links posted by a user. For instance, if a user posted www.youtube.com or www.p2p.wrox.com , it will allow them to click on the Label and proceed to the link in a new window. Could someone advise me how to work on it?

Codes

<
ahref=""><asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label></a><br/><br/>
I think you're looking for a nice simple solution and one that will give you good control over the HTML output. You're on the right track; the error indicates that "Bind" is a high powered method available on certain high powered controls. It's not available for the lighter controls like Label, you just need to use Eval.

You can even drop the span tag generated by the Label control by using the asp:Literal control instead. A label would render this as...

<a href="www.youtube.com"><span>www.youtube.com</span></a>

when what you really want is...

<a href="www.youtube.com">www.youtube.com</a>

and I believe using a literal with the Eval method should do the trick best.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
using href in xslt rajesh_css XSLT 0 September 18th, 2008 02:44 AM
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
Href in a string seran128 Classic ASP Professional 1 April 14th, 2006 11:05 PM
href darkhalf Javascript 2 November 20th, 2005 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.