简体   繁体   中英

Debugging CS0103 Error in Visual Studio code

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 class="form-group row justify-content-center">
                   <asp:Label runat="server" CssClass="col-md-2 col-form-label">Zip Code</asp:Label>
                      <div class="col-md-8">
                          <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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM