The Name 'Controlname' Does Not Exist in the Current Context

The name 'controlname' does not exist in the current context

Check your code behind file name and Inherits property on the @Page directive, make sure they both match.

The name [ControlName] missing in current context w/ Database connection

I found three better tutorials that, together, provide a sound construction method for standing up a gridview in ASP.NET with C#. I am not sure whether it is appropriate to post the tutorials here. I don't want it to appear that I am withholding information, but I also dont want it to look like I am advertising for the tutorials. The tutorial focus also in no way relates to the subject of this thread.

The name control name does not exist in the current context inline

Ok, you've created a local variable called lst but how the server markup can be aware about its existence???

At least, you'll need to declare it as a protected class field or property and it will be accessible by the markup part of your page:

class .... 
{
protected List<Services> lst;
}

BTW, it's sad that you need to do a for loop there: take a look at Repeater control.

The name control name does not exist in the current context

So my question is two-pronged, is there a simple way to create a web-app without the site.master, just a simple aspx page,

Yes:

  • Click New Project
  • Select ASP.NET Empty Web Application

Regarding the second problem

You have the inherits property pointing at the old designer file:

Inherits="VisionToPCC_XRef_Editor.Default"

I suspect that pointing at the correct designer file will fix this. This also explains why deleting and then re-adding the designer does not fix the problem.

ASP.NET Web Site The name does not exist in the current context

You can't access quantitytb directly because it is within a DataList. Similar to any data-bound container (gridview, repeater, formview, etc), you must target a specific item/row to find its child controls. If your datalist has 10 items in it, that means you'll have 10 occurrences of quantitytb - if you don't specify which one you're targeting, the code will throw an error.

If you're trying to modify the textbox that's the sibling of the clicked button, perhaps what you're looking for is this:

protected void addtocartbutton_Click(object sender, EventArgs e)
{
//Find the button that was clicked
Button addToCart = (Button)sender;

//Get the button's parent item, and within that item, look for a textbox called quantitytb
TextBox quantitytb = (TextBox)addToCart.Parent.FindControl("quantitytb");

//Set that textbox's text to "1"
quantitytb.Text="1";
}


Related Topics



Leave a reply



Submit