Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Properties and OnClick

Status
Not open for further replies.

ghesse

Programmer
Jun 16, 2003
51
US
Hello,

I'm having an issue here. In one of my codebehind files I have a property for the class. When the page loads and the user interacts with the page that property is bound to change value. My problem is when a user presses a particular button the original value of the property is used. It doesn't seem to be keeping up with the changing of the value. How do I keep the function of the onclick event for this button up to speed on the value of the property?

Thanks,
ghesse
 
maybe I should give you an example to make it easier:

private string myproperty;

public string property1
{
get
{
return myproperty;
}
set
{
myproperty = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
property1 = "Default Value";
}

protected void Button1_Click(object sender, EventArgs e)
{
property1 = "New Value";
DoSomething();
}

protected void Button2_Click(object sender, EventArgs e)
{
DoSomething();
}

Ok, so when I click button1 DoSomething works correctly with the new value. Then when I click button2 the default value is used. Even though I had already clicked button1 and property1 had been changed. Why isn't Button2 using the new value?

Thanks,
ghesse
 
oops, screwed up there...let me correct the Page_Load function:

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
property1 = "Default Value";
}
}


Sorry...that's what I meant.

ghesse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top