468,278 Members | 1,544 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,278 developers. It's quick & easy.

QyeryString related questions..

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!




Nov 17 '05 #1
5 1148
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" <i@d> wrote in message
news:OQ****************@TK2MSFTNGP09.phx.gbl...
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!



Nov 17 '05 #2
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" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
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" <i@d> wrote in message
news:OQ****************@TK2MSFTNGP09.phx.gbl...
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!




Nov 17 '05 #3
> 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" <i@d> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... 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" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
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" <i@d> wrote in message
news:OQ****************@TK2MSFTNGP09.phx.gbl...
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!





Nov 17 '05 #4
> 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?

Nov 17 '05 #5
In C#: using AssemblyName;
In VB.Net: Imports AssemblyName

--
HTH,

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

"Ivan Demkovitch" <i@d> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
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?

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by John Smith | last post: by
1 post views Thread by Adam Knight | last post: by
2 posts views Thread by Anthony Nystrom | last post: by
reply views Thread by connectrajesh | last post: by
102 posts views Thread by dreamznatcher | last post: by
reply views Thread by bsneddon | last post: by
8 posts views Thread by Krypto | last post: by
2 posts views Thread by Max2006 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.