MikeMCSD
asked on
Storing values without using Session var.
After the page loads and the 2 strings "rbid" and "rbmt" are validated, I want to "store"
them to be used later and then inserted into the database when Submit is clicked.
(I want these values to persist over any amount of time so using a Session variable won't work)
With VB, I used a Property.
What is the Object Oriented Programming approach (or the best way) in C# to do this?
If you have code examples, that would be great. Thanks
public partial class joinssl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string rbid = Request.QueryString["rbid" ];
string rbmt = Request.QueryString["rbmt" ];
// need to insert those values into the Database later, but don't want to
// rely on using Request.QueryString[] when the insertion occurs
them to be used later and then inserted into the database when Submit is clicked.
(I want these values to persist over any amount of time so using a Session variable won't work)
With VB, I used a Property.
What is the Object Oriented Programming approach (or the best way) in C# to do this?
If you have code examples, that would be great. Thanks
public partial class joinssl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string rbid = Request.QueryString["rbid"
string rbmt = Request.QueryString["rbmt"
// need to insert those values into the Database later, but don't want to
// rely on using Request.QueryString[] when the insertion occurs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Bob . .
what syntax do I use to retrieve the value later in the code, ex:
ViewState["rbid"] = Request.QueryString["rbid" ];
...
CreateProduct(newName.Text , ViewState["rbid"], . .
what syntax do I use to retrieve the value later in the code, ex:
ViewState["rbid"] = Request.QueryString["rbid"
...
CreateProduct(newName.Text
CreateProduct(newName.Text , ViewState["rbid"].ToString (),
or
CreateProduct(newName.Text , (int)ViewState["rbid"],
depending on the data type stored.
Bob
or
CreateProduct(newName.Text
depending on the data type stored.
Bob
ASKER
Looking back at some VB code, I was actually doing the same thing
with the viewstate using a Property:
Private Property CustomerID() As Integer
Get
Dim value As Integer = 0
If Not ViewState("CustomerID") Is Nothing Then
value = DirectCast(ViewState("Cust omerID"), Integer)
End If
Return value
End Get
Set(ByVal value As Integer)
ViewState("CustomerID") = value
End Set
End Property
Is it better to use a Property or does it not matter?
with the viewstate using a Property:
Private Property CustomerID() As Integer
Get
Dim value As Integer = 0
If Not ViewState("CustomerID") Is Nothing Then
value = DirectCast(ViewState("Cust
End If
Return value
End Get
Set(ByVal value As Integer)
ViewState("CustomerID") = value
End Set
End Property
Is it better to use a Property or does it not matter?
I love the idea of using properties, but only if they need to be public.
Bob
Bob
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public partial class joinssl : System.Web.UI.Page
{
//define some "global-class" variables that can be used anywhere inside this page
private string rbid = "";
private string rbmt = "";
protected void Page_Load(object sender, EventArgs e)
{
rbid = Request.QueryString["rbid"
rbmt = Request.QueryString["rbmt"
// need to insert those values into the Database later, but don't want to
// rely on using Request.QueryString[] when the insertion occurs
}
private void someMethod() {
//now in here you can use them again as needed
string blah = rbmt; //this value was set in the page_load method
}