QyeryString related questions..

I

Ivan Demkovitch

Hi!

I'm building my portal and I found that some times I need to dinamically
generate address.

Since I have many modules and each could have it's own parameters in order
to preserve other's modules stuff I try to preserve
Query string:

string GetQueryString()
{
string s = "";

foreach(string str in Request.QueryString)
s += str + "=" + Request.QueryString[str] + "&";

//If not empty then cut off last parameter:
if (s.Length != 0) s = s.Remove(s.Length-1, 1);
return s;
}

//add's parameter to passed query string. Or updates if was there.
string AddToQueryString(string str_QueryString, string str_Param, string
str_Value)
{

}


Then I add my parameters. Each module does same thing and this way user will
expirience full state maintenance when browse within single "page"


My questions:

1. Is it something common? And if yes then my functions most likely already
in .NET. What are they?

2. I don't like to have same function in each module, how can I move it out?
I remember there was a class which don't have to be initialized. What is
this class? I would use it for my common functions.

Thanks!
 
K

Kevin Spencer

If you want to make it a static (Shared) function, just get the Request from
the HttpContext:

VB.Net:

Dim Request As System.Web.HttpRequest
If Not IsNothing(System.Web.HttpContext.Current) then
Request = System.Web.HttpContext.Current.Request
End If

C#:

System.Web.HttpRequest Request
if (System.Web.HttpContext.Current != null)
Request = System.Web.HttpContext.Current.Request;

Note: It would be best to avoid using Modules, or, if this is the case here,
referring to classes as Modules. Modules are really there for backwards
compatibility, and should be replaced with classes. You can put a public
static method into a public class, and the class doesn't need to be
instantiated to use the method. Any of the members of HttpContext can be
grabbed from a static method, including Server, Page, Request, Response,
Application, Session, and a number of other less-commonly-used members.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.
 
I

Ivan Demkovitch

Thanks Kevin,

Thats what I need (because I think I need it)

I'm from desktop development and new to Web.

I wonder if this is what people do to preserve view state? Or is there
better way to do this.?

I refered to modules in my portal, this is actually Web controls.


Kevin Spencer said:
If you want to make it a static (Shared) function, just get the Request from
the HttpContext:

VB.Net:

Dim Request As System.Web.HttpRequest
If Not IsNothing(System.Web.HttpContext.Current) then
Request = System.Web.HttpContext.Current.Request
End If

C#:

System.Web.HttpRequest Request
if (System.Web.HttpContext.Current != null)
Request = System.Web.HttpContext.Current.Request;

Note: It would be best to avoid using Modules, or, if this is the case here,
referring to classes as Modules. Modules are really there for backwards
compatibility, and should be replaced with classes. You can put a public
static method into a public class, and the class doesn't need to be
instantiated to use the method. Any of the members of HttpContext can be
grabbed from a static method, including Server, Page, Request, Response,
Application, Session, and a number of other less-commonly-used members.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
The more I learn, the less I know.

Ivan Demkovitch said:
Hi!

I'm building my portal and I found that some times I need to dinamically
generate address.

Since I have many modules and each could have it's own parameters in order
to preserve other's modules stuff I try to preserve
Query string:

string GetQueryString()
{
string s = "";

foreach(string str in Request.QueryString)
s += str + "=" + Request.QueryString[str] + "&";

//If not empty then cut off last parameter:
if (s.Length != 0) s = s.Remove(s.Length-1, 1);
return s;
}

//add's parameter to passed query string. Or updates if was there.
string AddToQueryString(string str_QueryString, string str_Param, string
str_Value)
{

}


Then I add my parameters. Each module does same thing and this way user will
expirience full state maintenance when browse within single "page"


My questions:

1. Is it something common? And if yes then my functions most likely already
in .NET. What are they?

2. I don't like to have same function in each module, how can I move it out?
I remember there was a class which don't have to be initialized. What is
this class? I would use it for my common functions.

Thanks!
 
K

Kevin Spencer

I wonder if this is what people do to preserve view state? Or is there
better way to do this.?

In some cases, yes, you can preserve state by using static members. There
are quite a few other ways to perserve state as well, such as using
ApplicationState, SessionState, HttpContext, files, database, etc. You need
to determine the most appropriate mechanism to use based upon the
requirement of the application regarding whatever it is you want to
preserve. Basic rule of thumb: Always use the mechanism with the smallest
necessary scope. Static members have totally global scope, so watch out!
I refered to modules in my portal, this is actually Web controls.

I suspected that, hence my alternate possibility ("or, if this is the case
here, referring to classes as Modules").

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

Ivan Demkovitch said:
Thanks Kevin,

Thats what I need (because I think I need it)

I'm from desktop development and new to Web.

I wonder if this is what people do to preserve view state? Or is there
better way to do this.?

I refered to modules in my portal, this is actually Web controls.


Kevin Spencer said:
If you want to make it a static (Shared) function, just get the Request from
the HttpContext:

VB.Net:

Dim Request As System.Web.HttpRequest
If Not IsNothing(System.Web.HttpContext.Current) then
Request = System.Web.HttpContext.Current.Request
End If

C#:

System.Web.HttpRequest Request
if (System.Web.HttpContext.Current != null)
Request = System.Web.HttpContext.Current.Request;

Note: It would be best to avoid using Modules, or, if this is the case here,
referring to classes as Modules. Modules are really there for backwards
compatibility, and should be replaced with classes. You can put a public
static method into a public class, and the class doesn't need to be
instantiated to use the method. Any of the members of HttpContext can be
grabbed from a static method, including Server, Page, Request, Response,
Application, Session, and a number of other less-commonly-used members.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
The more I learn, the less I know.

Ivan Demkovitch said:
Hi!

I'm building my portal and I found that some times I need to dinamically
generate address.

Since I have many modules and each could have it's own parameters in order
to preserve other's modules stuff I try to preserve
Query string:

string GetQueryString()
{
string s = "";

foreach(string str in Request.QueryString)
s += str + "=" + Request.QueryString[str] + "&";

//If not empty then cut off last parameter:
if (s.Length != 0) s = s.Remove(s.Length-1, 1);
return s;
}

//add's parameter to passed query string. Or updates if was there.
string AddToQueryString(string str_QueryString, string str_Param, string
str_Value)
{

}


Then I add my parameters. Each module does same thing and this way
user
will
expirience full state maintenance when browse within single "page"


My questions:

1. Is it something common? And if yes then my functions most likely already
in .NET. What are they?

2. I don't like to have same function in each module, how can I move
it
out?
I remember there was a class which don't have to be initialized. What is
this class? I would use it for my common functions.

Thanks!
 
I

Ivan Demkovitch

preserve. Basic rule of thumb: Always use the mechanism with the smallest
necessary scope. Static members have totally global scope, so watch out!

Thanks!

This is only static functions, so I don't have to rewrite it every time.
I'm not going to store anything in public variables, only authentication...

public static works, but I need to include my class name every time I call
function.

Is there any way I could do it so I just call function?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top