0

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;

4
  • 1
    runat="server" implies web forms, and if that's true you want to use an <asp:TextBox instead of an <input type="text" element. It also matters quite a bit where that second code snippet is located. Commented May 24, 2022 at 19:15
  • @JoelCoehoorn You can use <input type="text" runat="server" /> in WebForms - it just means the runtime type is System.Web.UI.HtmlControls.HtmlInputText instead of WebControls.TextBox. Commented May 24, 2022 at 19:49
  • There isn't anything immediately wrong with the code you've posted - we need to see more to be able to tell you what's going on. Have you done a full rebuild and/or nuked your obj directory? Commented May 24, 2022 at 19:50
  • Also... why are you using WebForms in 2022? Commented May 24, 2022 at 19:51

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

add runat= 'server' to the text input

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.