I have created an ASP.NET class.
In that class i would like to use the Server.UrlEncode
.
Why intellisense is not helping me at all and instead of Server.UrlEncode
it displays the HttpServerUtility
?
I have already a reference to system.web
I have created an ASP.NET class.
In that class i would like to use the Server.UrlEncode
.
Why intellisense is not helping me at all and instead of Server.UrlEncode
it displays the HttpServerUtility
?
I have already a reference to system.web
Because the .Server
property of the page is an instance of HttpServerUtility
class.
http://msdn.microsoft.com/en-us/library/system.web.ui.page.server.aspx
To use UrlEncode
method outside the page, use the HttpUtility
class.
You can access that function through the HttpContext object. I guess your class is in a class library in which you should always check you have a context in case your code is called outside of a web context. Try this:
if (HttpContext.Current != null)
{
string sEncondedBit = HttpContext.Current.Server.UrlEncode("text & more txt");
}