When I try to access this value from the aspx page that uses the control, I get the following error:
Compiler Error Message: CS0122: 'ASP.Organization_Form_ascx.Name' is inaccessible due to its protection level
However I cannot seem to change the protection level of the textbox within the control. When I add this code:
<script language="c#" runat="server">
public TextBox Name;
</script>
I then get this error:
Compiler Error Message: CS0102: The class 'ASP.Organization_Form_ascx' already contains a definition for 'Name'
How do I go about changing the protection level of my TextBox so that I can access it in the aspx page that loads the control?
Thanks,
Alex
06-08-2005, 09:05 AM
persian_celina
hi there,
to change the protection level in the ascx level u should go for it this way:
in the .ascx codebehind Change "protected" to "public" like the orange part below:
public class mycontrol : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.TextBox Name;
:o ok?
and then in the .aspx page:
first u add ur Usercontrol on the webform,then in the codebehind , u should add the orange part :
public class WebForm5 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected WebApplication1.mycontrol mycontrol1;
private void Page_Load(object sender, System.EventArgs e)
{
mycontrol1.Name.Text="it works!";
// Put user code to initialize the page here
}
Then As u can c up there in the green line,the textbox is recognized by it's ID and properties of a normal textbox in the .aspx codebehind.
G'luck!
06-09-2005, 12:35 PM
hoyaabanks
Let's say I have a usercontrol that looks like this: