URL Parameter and C#

  • Thread starter Thread starter mo
  • Start date Start date
M

mo

Hi,

in java I have used the following to pass parameters with space in
them

<A href=xxx.htm?V1=<%escape("something with spaces")> this is the
link</A>

I am new to C# is there an equivalent link is C#? I have the
following:

<A href=xxx.htm?V1=<%# DataBiner.Eval(Container.DataItem, "Something
with space")%> > this is the link </A>

only the first characters before space is passed. any ideas?

Thanks,
Mo
 
Mo,

You would use the UrlEncode property on the Server property exposed by
the page, like so:

<A href=xxx.htm?V1=<%# Server.UrlEncode(DataBiner.Eval(Container.DataItem,
"Something with space"))%> > this is the link </A>

Hope this helps.
 
Thanks Nick,

Do I need a NameSpace or something (Sorry I am a novice) I get this
error:

Compiler Error Message: CS1502: The best overloaded method match for
'System.Web.HttpServerUtility.UrlEncode(string)' has some invalid
arguments

for
<a href='/ShowCat.aspx?Category=<%#
Server.UrlEncode(DataBinder.Eval(Container.DataItem,"Category"))%>&Size=
M' Target=Main>

Any Ideas?
 
i think if you make it

<a href='/ShowCat.aspx?Category=<%#
Server.UrlEncode(DataBinder.Eval(Container.DataItem,"Category").ToString())%
&Size=M' Target=Main>

then it'll work. (i just added the .ToString() to the Eval() call.)
 
Back
Top