Why this DataBind changes my code?

  • Thread starter Thread starter maury
  • Start date Start date
M

maury

Hello, I have a web form page with something like this
<a id="link" runat="server" href='<%# String.Concat("pag.aspx?
tipo1=1&amp;tipo2=2") %>'>xxx</a>

on the Page_Load, I have this code to execute the databind
link.DataBind();

but the generated code is far from I would like to be, I would like to
have this code
<a href="pag.aspx?tipo1=1&amp;tipo2=2" id="link">xxx</a>

instead I can see in the html source of the page
<a href="pag.aspx?tipo1=1&tipo2=2" id="link">xxx</a>

(this is a problem for me...)

any ideas?
 
Hello, I have a web form page with something like this
    <a id="link" runat="server" href='<%# String.Concat("pag.aspx?
tipo1=1&amp;tipo2=2") %>'>xxx</a>

on the Page_Load, I have this code to execute the databind
        link.DataBind();

but the generated code is far from I would like to be, I would like to
have this code
    <a href="pag.aspx?tipo1=1&amp;tipo2=2" id="link">xxx</a>

instead I can see in the html source of the page
    <a href="pag.aspx?tipo1=1&tipo2=2" id="link">xxx</a>

(this is a problem for me...)

any ideas?

Hm, I don't know why you may need it but you can try

&amp;amp;
 
Hm, I don't know why you may need it but you can try

&amp;amp;

GREAT! This is a great idea! It works!!!!

But can you explain me what's the problem with my code?

Thanks
 
GREAT! This is a great idea! It works!!!!

But can you explain me what's the problem with my code?

Thanks

&amp; is an html code of & and it seems that IDE replaced it here
because it thinks you makes an url. Why do you use String.Concat
method there? Maybe this is the reason
 
&amp; is an html code of & and it seems that IDE replaced it here
because it thinks you makes an url. Why do you use String.Concat
method there? Maybe this is the reason

This is only an example page, the real code is much more
complicated...

Note that also the html control <img ...runat='server'
has the same behaviour but <asp:Image
web control isn't affected by this problem, it renders fine...

bye
 
This is only an example page, the real code is much more
complicated...

Note that also the html control  <img ...runat='server'
has the same behaviour but <asp:Image
web control isn't affected by this problem, it renders fine...

bye

Please ignore my last comment. This, of course, comes not from IDE,
but from ASP.NET. When html control has runat="server" ASP.NET does
html-decoding. Try to remove runat="server" from the link and see what
happens.
 
Back
Top