locked
WebForms Error." RRS feed

  • Question

  • User1421620300 posted

    Can someone help me to understand why i keep receiving tis type of error in my applications. And how can this be resolved? Thanks . markus33

    Severity Code Description Project File Line Suppression State
    Error CS0103 The name 'inputFirstname' does not exist in the current context DynamicSQL Stored_SP V:\msdn tutorials\DynamicSQL Stored_SP\DynamicSQL Stored_SP\DynamicSQLInStoredProcedure.aspx.cs 35 Active
    Error CS0103 The name 'inputFirstname' does not exist in the current context DynamicSQL Stored_SP V:\msdn tutorials\DynamicSQL Stored_SP\DynamicSQL Stored_SP\DynamicSQLInStoredProcedure.aspx.cs 38 Active
    Error CS0103 The name 'inputLastname' does not exist in the current context DynamicSQL Stored_SP V:\msdn tutorials\DynamicSQL Stored_SP\DynamicSQL Stored_SP\DynamicSQLInStoredProcedure.aspx.cs 42 Active

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using DynamicSQL_Stored_SP;
    using System.Globalization;
    using System.Web.UI;

    namespace DynamicSQL_Stored_SP
    {
    public partial class DynamicSQLInStoredProcedure : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    { }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
    string connectionStr = ConfigurationManager
    .ConnectionStrings["connectionStr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(connectionStr))
    {
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "spSearchEmployeesGoodDynamicSQL";
    cmd.CommandType = CommandType.StoredProcedure;

    if (inputFirstname.Value.Trim() != "")
    {
    SqlParameter param = new SqlParameter("@FirstName",
    inputFirstname.Value);
    cmd.Parameters.Add(param);
    }

    if (inputLastname.Value.Trim() != "")
    {
    SqlParameter param = new SqlParameter("@LastName",
    inputLastname.Value);
    cmd.Parameters.Add(param);
    }

    if (inputGender.Value.Trim() != "")
    {
    SqlParameter param = new SqlParameter("@Gender",
    inputGender.Value);
    cmd.Parameters.Add(param);
    }

    if (inputSalary.Value.Trim() != "")
    {
    SqlParameter param = new SqlParameter("@Salary",
    inputSalary.Value);
    cmd.Parameters.Add(param);
    }

    con.Open();
    SqlDataReader rdr = cmd.ExecuteReader();
    gvSearchResults.DataSource = rdr;
    gvSearchResults.DataBind();
    }
    }
    }
    }

    Saturday, November 2, 2019 9:45 PM

Answers

  • User-37275327 posted

    Check inputFirstname has "Runat="Server"" on the html markup.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 4, 2019 1:04 AM
  • User753101303 posted

    Hi,

    The needed declaration should be automatically created for you in a mypage.designer.aspx.cs file. Check this file to see if this is generated properly. This is directly inside a runat form or are those fields shown inside another server side control ???

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2019 2:50 PM
  • User475983607 posted

    Markus33

    Is this the correct html coding format!

    You are implementing HTML controls which is not the standard ASP.NET Web Form server controls.  It's not clear why you are taking the approach and therefore the community has no basis to provide a recommendation.  IMHO, if you are building a Web Forms application you should add server controls to the web form.  If you are building a web application that uses client side technologies like Bootstrap and JavaScript then you should build an MVC application.

    If you want a community code review then post all the relevant code so the community can have, at least, a slight idea of how your code is designed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2019 2:56 PM

All replies

  • User475983607 posted

    Web forms has several files that make up a singe page.  One of those files keeps track of the server controls that are added the web form.  The compiler error message indicates the inputs do not exist.  The construct indicates you are using HTML controls.

    if (inputFirstname.Value.Trim() != "")
    {
      SqlParameter param = new SqlParameter("@FirstName",
      inputFirstname.Value);
      cmd.Parameters.Add(param);
    }

    Make sure the HTML controls have the runat="server" attribute.
      

    Sunday, November 3, 2019 12:04 PM
  • User-37275327 posted

    Check inputFirstname has "Runat="Server"" on the html markup.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 4, 2019 1:04 AM
  • User1421620300 posted

    The "Runat="Server""  code is available in all of the input feilds of the project. But it still throws error! Markus.

    Saturday, November 16, 2019 3:14 PM
  • User1421620300 posted

    See the code below. Is this the correct html coding format! Markus

    <h3>Employee Search Form</h3>
    </div>
    <div class="panel-body">
    <div class="form-group">
    <label for="inputFirstname" class="control-label col-xs-2">
    Firstname
    </label>
    <div class="col-xs-10">
    <input type="text" runat="server" class="form-control"
    id="inputFirstname" placeholder="Firstname" />
    </div>
    </div>

    Wednesday, November 20, 2019 12:52 AM
  • User753101303 posted

    Hi,

    The needed declaration should be automatically created for you in a mypage.designer.aspx.cs file. Check this file to see if this is generated properly. This is directly inside a runat form or are those fields shown inside another server side control ???

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2019 2:50 PM
  • User475983607 posted

    Markus33

    Is this the correct html coding format!

    You are implementing HTML controls which is not the standard ASP.NET Web Form server controls.  It's not clear why you are taking the approach and therefore the community has no basis to provide a recommendation.  IMHO, if you are building a Web Forms application you should add server controls to the web form.  If you are building a web application that uses client side technologies like Bootstrap and JavaScript then you should build an MVC application.

    If you want a community code review then post all the relevant code so the community can have, at least, a slight idea of how your code is designed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2019 2:56 PM