c# - How do I get the HTML encoding to work in my ASPX page? -


i have following code in asp gridvidiew:

<asp:hyperlink id="hlpstnnum"  cssclass="ordref" text='<%# databinder.eval(container.dataitem, "pstnnum")%>'  runat="server" tooltip='please click here view full record details' navigateurl='<%#"https://the url here searches/advancedsearchresults.asp?supplierid=" + eval("supplierid") + "&amp;display1=is%20number&amp;display2=supplier&amp;display3=product&amp;display4=supplier%20order%20number&amp;order1=order%20date&amp;pstnnum=" + eval("pstnnum")%>' /> 

i think visual studio 2012 playing semicolons in query string part (from "pstnnum=" + eval("pstnnum")%>' />" , tried escape them \ (that keeps vs happy), browser leaves 1 of slashes in @ each escape.

not sure best practice here im still cutting coding teeth...

i think more appropriate approach this:

<asp:hyperlink id="hlpstnnum"     cssclass="ordref"     text='<%# databinder.eval(container.dataitem, "pstnnum")%>'     runat="server"     tooltip='please click here view full record details'     navigateurl='<%#server.htmlencode("https://the url here searches/advancedsearchresults.asp?supplierid=" + eval("supplierid") + "&display1=is number&display2=supplier&display3=product&display4=supplier order number&order1=order date&pstnnum=" + eval("pstnnum"))%>' /> 

note use of server.htmlencode , use of actual values want rather directly encoded values. make easy build in visual studio, ensure gets encoded when it's rendered.

edit

after more research microsoft's code found base rendercontents method hyperlink class going encode you. method, internally, calls 1 called resolveclienturl, looks this:

public string resolveclienturl(string relativeurl) {     if (this.designmode && this.page != null && this.page.site != null)     {         iurlresolutionservice urlresolutionservice = (iurlresolutionservice)this.page.site.getservice(typeof(iurlresolutionservice));         if (urlresolutionservice != null)         {             return urlresolutionservice.resolveclienturl(relativeurl);         }     }     if (relativeurl == null)     {         throw new argumentnullexception("relativeurl");     }     string virtualpathstring = virtualpath.getvirtualpathstring(this.templatecontrolvirtualdirectory);     if (string.isnullorempty(virtualpathstring))     {         return relativeurl;     }     string text = this.context.request.clientbasedir.virtualpathstring;     if (!urlpath.isapprelativepath(relativeurl))     {         if (stringutil.equalsignorecase(text, virtualpathstring))         {             return relativeurl;         }         if (relativeurl.length == 0 || !urlpath.isrelativeurl(relativeurl))         {             return relativeurl;         }     }     string = urlpath.combine(virtualpathstring, relativeurl);     text = urlpath.appendslashtopathifneeded(text);     return httputility.urlpathencode(urlpath.makerelative(text, to)); } 

since you're url not relative should fall way last line, return statement, shouldn't have encode @ all. changes code this:

<asp:hyperlink id="hlpstnnum"     cssclass="ordref"     text='<%# databinder.eval(container.dataitem, "pstnnum")%>'     runat="server"     tooltip='please click here view full record details'     navigateurl='<%#"https://the url here searches/advancedsearchresults.asp?supplierid=" + eval("supplierid") + "&display1=is number&display2=supplier&display3=product&display4=supplier order number&order1=order date&pstnnum=" + eval("pstnnum")%>' /> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -