Hi Mark,
Thanks for posting in the community!
From your description, you'd like to get some suggestions on how to refer a
certain control(contained in a web page)'s value from a class module,yes?
If there is anything I misunderstood, please feel free to let me know.
As for this problem, here are my suggestions:
Generally, in a ASP.NET web page's code-behind class file, if you want to
get a webcontrol(such as textbox) 's value, you could use the code as:
this.TextBox1.Text = ....
However, if we want to retreive a certain page's sub control 's value in a
certain class module, we could use the following two means:
1. define a property for the page class which delegate the certain
webcontrol member, then in the class module, you can get the page's control
's value via the public property. For example:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtA;
public string TextA
{
get{return txtA.Text;}
set{txtA.Text = value;}
}
.............
}
Then we can define a method in the class module to get the property's value
from a certain page, just like:
public static void GetPageTextBoxValue(Page page, string property)
{
string value = (string)DataBinder.Eval(page,property);
page.Response.Write("<br>"+property +": " + value);
}
2. If you'd like to directly access the certain control's value via its
control's Id, you can pass the certain page class's instance into the class
module's method and do any operations on it. For example:
Still use the
public class WebForm1 : System.Web.UI.Page as above one,
In class module , we define the method like:
public static void GetPageTextBoxValue(WebForm1 page)
{
string value = page.txtA.Text;
page.Response.Write("<br>txtA.Text: " + value);
}
Thus, it'll looks much simpler.
Please check out my suggestions. If you feel anything unclear, please feel
free to let me know.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)