Re: Setting a Default Value



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: C# Static string appending problem.
    ... built up which is being dumped out when the code executes multiple times. ... VerifyPOLineUnique STARTED ... public static string VerifyPOLineUnique(TypedXmlDocument rootNode, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# Static string appending problem.
    ... VerifyPOLineUnique STARTED ... when I execute it a second time, ... public static string VerifyPOLineUnique(TypedXmlDocument rootNode, ...
    (microsoft.public.dotnet.languages.csharp)
  • GetDirectories throws PathTooLongException
    ... DoWorkEventArgs e, string startDirectoryLongForm, string ... numFiles += CountFilesInDirectory(backgroundWorker, e, ... static extern uint GetLongPathName( ... public static string ToLongPathName ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing values to a property in C#?
    ... Public Shared Property Settings(ByVal Item As String) As String ... wich are equivalent to default properties in VB.Net. ... public static string Settings ... ClassName is the name of the class the indexer is declared in. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ASCII Hex string to character conversion
    ... Base64 is much more efficient. ... public static String encodeHexString{ ... int numBytes = hexTextlength/2; ...
    (comp.lang.java.programmer)

Loading