Re: Setting a Default Value



Hmm what do you mean by "if your default value needs to come out of the
database but it does not change"?

Basically my app could be called using the following URL:
http://www.mydomain.com/myapp.aspx?id=1234

Or it could be called using this URL:
http://www.mydomain.com/myapp.aspx?id=1234&myvariable=AB123NDOWQ

If the former is used (without a myvariable in the URL) then I want to
default myvariable to a certain value. But the value I want to default to
may change depending on the ID in the URL. In other words I could also have
the following URLs:

http://www.mydomain.com/myapp.aspx?id=1235
http://www.mydomain.com/myapp.aspx?id=1236
http://www.mydomain.com/myapp.aspx?id=1237

Thanks
Brad


"Peter Bromberg [C# MVP]" <pbromberg@xxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:F0D8835C-8353-4FAB-BB00-C9C5F2DA8D45@xxxxxxxxxxxxxxxx
if your default value needs to come out of the database but it does not
change,
the make the Sql call from within Application_Start in Global.asax. You
can
then either store it in Application state or in a static field in the
Global
class.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Brad Baker" wrote:

I'm a bit of an asp.net/csharp newbie so please bear with me. If I
understand you correctly, I would call: SafeSessionGet(myvariable) to get
the query string value (or assign a default value) each time I needed to
reference myvariable?



Assuming that's correct, I'm not sure if that's the best solution as I am
going to assign the default value through a database query. So for
instance
I might have the following (again in pseudo code):



if myvariable == null {

run the following SQL query: select * from table where x = 1

myvariable = first result of sql query

}



So for instance if I needed to call myvariable from four different
sections
of my code I would have to run the sql query four times? Isn't that
fairly
inefficient performance wise? I was thinking of trying to set myvariable
once using one SQL query then reuse it throughout my application. I was
hoping to do that through some sort of global variable (I'm not sure
csharp
has anything like that or not though).



Maybe I am misunderstanding you or maybe there is some other approach I'm
overlooking. Any additional guidance you could provide would be sincerely
appreciated. :)



Thanks Again,

Brad



"sloan" <sloan@xxxxxxxxx> wrote in message
news:Ocvto0kmHHA.3952@xxxxxxxxxxxxxxxxxxxxxxx
Put this in a class somewhere.



public static string SafeSessionGet(Page pageObj, string requestKey,
string defaultValue)
{
if (pageObj.Request[requestKey] == null)
{
return defaultValue;
}
else
{
return pageObj.Request[requestKey].ToString ();
}
}




public static string SafeSessionGet(Page pageObj, string requestKey)
{
return SafeSessionGet ( pageObj , requestKey , string.Empty ) ;
}





You could write a generics version of this in 2.0 if you wanted, but
that
might be overkill.


private string m_empUUID = string.Empty;

public void Page_Load(object sender, EventArgs e)
{


m_empUUID = SafeSessionGet ( Page , "empkey" ) ;
//or

m_empUUID = SafeSessionGet ( Page , "empkey" ,
"00000-00000-000000000-000000000" ) ;



}







"Brad Baker" <brad@xxxxxxxxxxxxx> wrote in message
news:ubX6fskmHHA.3952@xxxxxxxxxxxxxxxxxxxxxxx
I have an asp.net/csharp application that requires a particular
variable
to
work properly. This variable is usually passed via a query string in
the
URL
when the application is first run but under certain circumstances the
query
string may not contain the variable. So I need some way of
establishing a
default value if one isn't set.

Is there some way I can set a query string on page_load OR is there
some
way
I can use a global variable which is accessible throughout my
application
instead? In pseudo code something like:

public void Page_Load(object sender, EventArgs e)
{
if (querystring == null)
{
global myvariable = "somevalue";
} else {
global myvariable = querystring;
}
}

protected void dostuff(object sender, EventArgs e)
{
if (myvariable == "foo")
{
// do stuff
}
}

Hopefully this makes sense - for clarity sake I have tried to simplify
my
situation as much as possible.

Thanks
Brad









.



Relevant Pages

  • Re: [PhP - dB] About Formatting a Date Result
    ... what you are getting is an unformatted string, ... in the sql query that creates the table row it appears some severe lack of ... the database is slightly smaller and faster, int compared to a text field. ... and can format your date to that used, in the config files, for any user ...
    (php.general)
  • Re: Setting a Default Value
    ... the make the Sql call from within Application_Start in Global.asax. ... the query string value each time I needed to ... going to assign the default value through a database query. ... run the following SQL query: select * from table where x = 1 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: filtering bound data based on custom field
    ... If you are querying a numeric field in a database you can't use a string ... value for the SQL query. ... Cast your string value to a Long: ... then use that in your SQL string. ...
    (microsoft.public.outlook.program_forms)
  • Re: Recordset problem
    ... Parse and loop through passed parameters and create a SQL query ... Run that string using sp_executesql and store results in a temp ... Please reply to the newsgroup. ...
    (microsoft.public.inetserver.asp.general)
  • Re: Extremely long SQL Array
    ... DIM SQLStr As String ... that has an extremely long SQL query array. ... Dim cellValue1 As String ...
    (microsoft.public.excel.programming)