0

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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Muha18
  • 57
  • 5
  • Have you checked [here](https://stackoverflow.com/questions/706603/the-name-controlname-does-not-exist-in-the-current-context) or [here](https://stackoverflow.com/questions/24008549/the-name-does-not-exist-in-the-current-context-in-aspx-page)? – General Grievance Dec 25 '21 at 16:15
  • I don't see in code where you defined ddlZip? – Albert D. Kallal Dec 25 '21 at 16:19

2 Answers2

0

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

0

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

Muha18
  • 57
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 28 '21 at 23:13