Yeah... I wrote an example up before seeing Jimi's example.
But here is mine... Same bat time, same bat channel.
ASPX
<HTML>
<HEAD>
<title>ViewStat eTest</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="C#" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P><asp:textb ox id="TextBox1" runat="server"> </asp:textbox>&nb sp;(Put a
Number In
Here, and click the Button Below)</P>
<P><asp:butto n id="Button1" runat="server"
Text="ButtonONE "></asp:button></P>
<P><asp:butto n id="Button2" runat="server" Text="ButtonTWO "
Visible="False" ></asp:button></P>
</form>
</body>
</HTML>
..cs code behind:
public int SelectedRecordI D
{
get
{
if (ViewState["SelectedRecord ID"] != null)
return Convert.ToInt32 (ViewState["SelectedRecord ID"]);
else
return -1;
}
set
{
ViewState["SelectedRecord ID"] = value;
}
}
private void Button1_Click(o bject sender, System.EventArg s e)
{
int whatsMyValue = this.SelectedRe cordID;
this.SelectedRe cordID = int.Parse(this. TextBox1.Text);
this.Button1.Vi sible = false;
this.Button2.Vi sible = true;
}
private void Button2_Click(o bject sender, System.EventArg s e)
{
int whatsMyValue = this.SelectedRe cordID;
this.SelectedRe cordID = int.Parse(this. TextBox1.Text);
}
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
if (!Page.IsPostBa ck)
{
this.SelectedRe cordID = -999; // use -999 for the PageLoad
}
}
"Jimi200478 " <JM*********@gm ail.com> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
Adam Sandler:
You are going to have to store "MyName" in either ViewState or Session
if you want it to survive a PostBack. Both mine and Sloan's examples
are the same, just different syntax. Sloans example demonstrates how to
use a property in .NET, but it doesnt answer base question which is
"how do i make the value survive a postback". The answer to that
question is viewstate or session. if you do want to have a variable on
your page called myname, you will have to do something like this:
in C#:
private string _MyName;
public string MyName
{
get
{
_MyName = ViewState["MyName"].ToString();
return _MyName;
}
set
{
_MyName = value;
ViewState["MyName"] = _MyName;
}
}
if the property is followed by an equals sign, then it knows to "set"
the value. if it is called without an equals sign, the property knows
to "get" the value. see below:
Setting MyName :
MyName = "John"
Getting MyName :
MsgBox(MyName)
Truthfully, at the end of it all, it doesnt matter how you do it, all
that matters is that you use viewstate or session to keep your value
alive. well, good luck!