ASP.Net C# - Class Advice

  • Thread starter Thread starter TisMe
  • Start date Start date
T

TisMe

Hi All,

Can someone please advise how I make controls on the page accessible
to class myClass, as defined below?

Any help will be appreciated!

Thank you.

Simon.


public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
// Do stuff with controls - No problem...
lblMessage.Text = "Hello World";
}

}

public class myClass : System.Web.UI.Page
{

public myClass
{
}

public void setLabel
{
// This doesn't work...(Doesn't exist in the current
context)
lblMessage.Text = "Hello Again World!";

// Neither does this...(Null reference exception)
Label lblMess = new Label();
lblMess = (Label)FindControl("lblMessage");
lblMess.Text = "Hello Again World";
}

}
 
They have to be members of the class. In your first example, the class
definition is partial, which means that the label is in another part of the
class definition. Apparently, there is no label member in your second
(non-partial) implementation.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
They have to be members of the class. In your first example, the class
definition is partial, which means that the label is in another part of the
class definition. Apparently, there is no label member in your second
(non-partial) implementation.

Hi, thanks for this - So where have I gone wrong? (e.g. What should I
have done?)

Simpler example:

1) I drag labelX onto the page
2) Code myClass (Outside of the _default class for the page)
3) I now want to change a property of labelX, from a method within
myClass - How can I do this?

Thank you.
 
Back
Top