HTML quotes problem

  • Thread starter Thread starter Tim Mulholland
  • Start date Start date
T

Tim Mulholland

I have an issue i can work around, but i'm trying to figure out what i'm
"supposed" to do.

i have a line of HTML/ASP.NET code inside a repeater that is something like
this

<a href="page.aspx?s=<%# DataBinder.Eval(Container, "DataItem.TheData")
%>">Text</a>

This code executes perfectly, and does exactly what i want. When i try to
switch from HTML view to Design view, VS.NET2003 yells at me saying i need
to quote something differently. So, i figured i'd change the quotes...
well.. i can't change the "DataItem.TheData" to 'DataItem.TheData' because
thats a C# character literal, but with too many characters, and it doesn't
like that. I can change the "page.aspx?s= ... "> to be 'page.aspx?s=...'>
but that breaks some of my links that actually have the ' character in their
address.
So what do i do?
Whats the "proper" way to do this so i can actually switch back and forth
between HTML view and Design view without any hassle?

Thanks in advance!

Tim
 
Attaching something i use currently.... doesnt give me the annoying quotes
message

<asp:TemplateColumn>
<ItemTemplate>
<P align="center">
<asp:HyperLink ImageUrl="../Images/edit.gif" NavigateUrl='<%#
"CA_EditSubCategory.aspx?SubCatID=" +
DataBinder.Eval(Container.DataItem,"SubCategoryID") %>' runat="server"
ID="Hyperlink1"/>
</P>
</ItemTemplate>
</asp:TemplateColumn>

HTH

HD
 
i don't have my code here in front of me, but i'm guessing that this code
will output an anchor tag with double quotes around the href instead of
single quotes? I ask because you have single quotes around the NavigateUrl
property and i just want to make sure (though, i guess i'm just being lazy
and i could test it myself when i get home - but i figured i'd ask :) )

Thanks for your help

Tim
 
href can be assigned a URL string with a single quote ' or a double quote ".
no issues bout that

Chao,

HD
 
Hi Tim,

Thank you for using Microsoft Newsgroup Service. As for the question you
mentioned, I think Hermit's suggestion is quite correct. In case that you
want to use some quote ("") in the <%# %> bound, you should use '' to
include the <%# %> rather than use "", For example:
<ItemTemplate>

<asp:HyperLink NavigateUrl='<%# "target.aspx?id="
+DataBinder.Eval(Container.DataItem,"id")%>' runat="server"
ID="lnkNav">view</asp:HyperLink>

</ItemTemplate>

But be careful that don't include other text in the '' beside the <%# %>,
such as:

<asp:HyperLink NavigateUrl='other text<%# "target.aspx?id="
+DataBinder.Eval(Container.DataItem,"id")%>' runat="server"
ID="lnkNav">view</asp:HyperLink>

That'll cause all the expression between '' be analyzed as a normal string.
The <%# ........%> bound will be output as plain text.



Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Tim,

Have you tried my suggestion in the last reply or have you resolved your
problem? Please feel free to let me know if you have any problem on it.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Tim,

Thanks for your response. I'm glad that you've resolved the problem.


Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top