skip to Main Content

I’m trying to add a new seller into database but all the values i get from the input text are null

this is the form

<div class="mb-3">
                <label for="SNameTb" class="form-label">Seller FirstName</label>
                <input type="text" class="form-control" id="Snametb" runat="server">
            </div>

And this how i’m trying to get the values

string Sname = Snametb.Value;

2

Answers


  1. You missing the closing "/> in that input box.

    So, this:

    <div class="mb-3">
        <label for="SNameTb" class="form-label">Seller FirstName</label>
        <input type="text" class="form-control" id="Snametb" runat="server" value="" />
    </div>
    
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    

    and button click code:

    protected void Button1_Click(object sender, EventArgs e)
    {
        Debug.Print("Text box value = " + Snametb.Value);
    }
    

    So, add the "/>" to your markup (maybe a cut+paste issue).

    And not required, but good idea to add the value="" attribute also.

    Login or Signup to reply.
  2. add runat= 'server' to the text input

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search