TextBox Protection Level

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: TextBox Protection Level

  1. #1
    Join Date
    Mar 2004

    TextBox Protection Level

    I have a webcontrol mycontrol.ascx that has the following textbox:

    <asp:TextBox ID="Name" runat="server" Columns="15" />

    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;

    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?



  2. #2
    Join Date
    Mar 2004
    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;

    private void Page_Load(object sender, System.EventArgs e)

    // Put user code to initialize the page here


    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.


  3. #3
    Join Date
    Mar 2004
    Let's say I have a usercontrol that looks like this:

    <LSB:OrderItem id="db5" runat="server" Name="Cowbells" Quantity="100|150|other" />

    I can access the Quantity Variable in code with:


    This works because Quantity then sets a variable called Qty within the usercontrol. The above code returns and interger and works.

    Now lets say I have a string variable that looks like this:

    string myString = "db5";

    Is there a way to use this string to reference the usercontrol? How can I get at db5.Qty using this string? I want to be able to do something like:

    string myString = "db5";

    Response.Write( "Quantity: " + myString.Qty );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center