gizgok
gizgok

Reputation: 7649

How to access an ASP Control in a class file

I have a asp Textbox control in my .aspx page. I have a .cs class file , not the code behind file. I want to access this textbox control in this .cs file. I know I can pass it as a parameter.But I'm curious to know if I can do it through some reference way or something.

Upvotes: 0

Views: 1997

Answers (2)

Dan Dumitru
Dan Dumitru

Reputation: 5423

There is another scenario.

If you have a .cs page like BasePage.cs that inherits from System.Web.UI.Page, and if your code-behind class inherits from this BasePage, then in the BasePage.cs you can gen a reference to your textbox through FindControl:

TextBox txtName = (TextBox)this.FindControl("txtName");

But in a totally unrelated class it's as you suspected, the only way is to pass it as a parameter.

Upvotes: 1

nitropropain
nitropropain

Reputation: 26

Only as parameter or from code behind class.. Seems no other way

Upvotes: 0

Related Questions