Home > Back-end >  Debugging CS0103 Error in Visual Studio code
Debugging CS0103 Error in Visual Studio code

Time:12-29

Hi i am creating a dropdown list and inserting values programmatically from the code behind, however i am repeatedly getting the error CS0103. However my program and web page is running completely fine, but it is just bothering me and was wondering if there exist a way to suppress those error messages or maybe i am missing something.

Error: CS0103 The name 'ddlzip' does not exist in the current context

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace bse20bftmoviestore.tutorials.week3
{
    public partial class formSample : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)//When page is loaded everytime
        {
  
            txtFname.Focus();
            
            if (!Page.IsPostBack)//When page is first loaded
            {
                //Code behind to create items in the dropdown
                ListItem li1 = new ListItem("Select zip code", "-1");
                ListItem li2 = new ListItem("1111", "1");
                ListItem li3 = new ListItem("2222", "2");
                ListItem li4 = new ListItem("3333", "3");
                ddlzip.Items.Add(li1);
                ddlzip.Items.Add(li2);
                ddlzip.Items.Add(li3);
                ddlzip.Items.Add(li4);

            }
        }
    }
}

My dropdown list in the web form:

<!--zip code title and dropdown list (programmatically defined)-->
                <div >
                   <asp:Label runat="server" CssClass="col-md-2 col-form-label">Zip Code</asp:Label>
                      <div >
                          <asp:DropDownList ID="ddlzip" CssClass="form-control" runat="server"></asp:DropDownList>
                      </div>
                </div>
<!--End of zip code title and dropdown list (programmatically defined)-->

Error: CS0103 The name 'ddlzip' does not exist in the current context

CodePudding user response:

sometimes closing and then reopening the solution work. the other solution is removing bin and obj folder and build project again. these solutions worked for me

CodePudding user response:

The solution to this question is to link the both the CodeFile and CodeBehind in .aspx page title.

  • Related