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 curiou开发者_高级运维s to know if I can do it through some reference way or something.
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.
Only as parameter or from code behind class.. Seems no other way
精彩评论