Call function

  • Thread starter Thread starter Christian Ista
  • Start date Start date
C

Christian Ista

Hello,

I have a class. I create an instance of this class in Page_Load event.
Somewhere in the page I'd like to execute an a function (public) member of
this class. This function return a string. How can I call this function ?

Thanks,


C.
 
you can declare your class variable as a member variable to the page class
you're implementing. Create an instance in the OnLoad(or the event handler
for this); then any code the happens after OnLoad can access your class
instance: Assume your .aspx page has a textbox(id=txtOutput) and a
button(id=btnSubmit):

public class MyPage : Page
{
private MySuperClass _superClass = null;
protected Button btnSubmit;
protected TextBox txtOutput;

protected override void OnLoad(System.EventArgs e)
{
base.OnInit(e);
_superClass = new MySuperClass();
}

protected void btnSubmit_Click(object sender, System.EventArgs e)
{
if (_superClass != null)
{
txtOutput.Text = _superClass.MyPublicMethodThatReturnsAString();
}
}

}
 
Back
Top