Unable to access a control property - Stack Overflow..

N

Nelson F.

I've made a user control (ascx and ascx.cs) that works fine if I use a
session var to pass it value. However, I'd much prefer to set a property
instead so I added a property. The problem is that when I try to access the
property, it generates a StackOverflowException. See the snip from my source

---<snip>----

public string SelectedTab
{
get{ return SelectedTab; }
set{ SelectedTab = value; }
}

private void Page_Load(object sender, System.EventArgs e)
{
if (SelectedTab != null) // Stack exception here.
{
//....do something
}
}

---<snip>---

Am I doing something wrong?
 
I

Iain

You are returning a SelectedTab.

SelectedTab is a property which returns SelectedTab.

Hence you have infinite recursion.

private String mSelectedTab;

public string SelectedTab
{
get{ return mSelectedTab; }
set{ mSelectedTab = value; }
}

would work admirably.

Iain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top