You must Sign In to post a response.
  • Category: ASP.NET

    HTML textbox and button using asp.net

    hello i have asp.net login page and i am using html button and text box.
    but html text box (input) and button not work in asp.net page..
    how to use asp.net page in HTML text(input) and button ..

    1.- design page--
    <input type="text" placeholder="Username" id ="txtid" runat="server">
    <input type="password" id ="txtpass" runat="server" placeholder="Password" />

    <span class="state" id ="btnlogin" runat="server">Log in</span>

    2.- coding page -- ???


    please provide example how to make login page in asp.net using html text box and button with sql server (for database)
  • animated-login-form (345283-1-animated-login-form.zip)
  • #768083
    Hi Arvind,

    Have you coded what action to be performed when the button clicked?
    I mean in your design page you have coded for button:

    <span class="state" id ="btnlogin" runat="server">Log in</span>


    But when the button got click which function should I call?
    so you need to modify the above code like,


    <span class="state" id ="btnlogin" runat="server" onServerClick="btn_Click">Log in</span>


    Then we need to write coding for the Button click once called that function in cs page:


    protected void btn_Click(object sender, EventArgs e)
    {
    // your logic whether inserting or validating the user.
    }



    Kindly let us know whether it clears your doubt.

    Thanks,
    Mani

  • #768084
    thankss sir ji ...i have try its ..
    one more question ..
    how to use text box for input

    string qry = "SELECT * FROM login_table WHERE (eid = '" +????how to use html text box???? + "')AND (epass = '" + ????how to use html text box????? + "')";
    SqlDataAdapter da = new SqlDataAdapter(qry, con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    if (ds.Tables[0].Rows.Count > 0)
    {
    Response.Redirect("afterlogin.aspx");
    //Session["eid"] = TextBox1.Text;
    }
    else
    {
    Page.RegisterClientScriptBlock("saved", "<script language='javascript' type='text/javascript'>alert('invailid login .');</" + "script>");
    return;
    }


    because there are not show my textbox name for coding ==>>
    id ="txtid" and id ="txtpass"

    Class1.cs.txt

    Delete Attachment

  • #768086
    Hi Arvind,

    We have two ways to implement the HTML Text box values into Sql Queries.
    Choose which adapts your requirement.

    Suppose you have Text boxes in a HTML,

    <form id="form1" runat="server">

    User ID:<input type="text" id="txtName" name="Name" value="" />
    Password: <input type="text" id="txtpwd" runat="server" value="" />

    <asp:Button Text="Submit" runat="server" OnClick="Submit" />
    </form>


    Then you can perform Request Form Collection Object in .NET


    protected void Submit(object sender, EventArgs e)
    {

    string UserName= Request.Form["Name"]; // Name specified in the HTML Tag

    string Pwd= txtpwd.Value;

    }


    Then you can pass this to the sql query string.

    Second Method Directly passing the parameter in the query,


    string query = string.Format("SELECT * from login_table Where eid= '{0}' AND epass='{1}'", TextBox1.Text,TextBox2.Text);


    Hope the second method was simple.

    Thanks,
    Mani

  • #768090
    By default, HTML elements on an ASP.NET Web page are not available to the server; they are treated as opaque text that is passed through to the browser. However, by converting HTML elements to HTML server controls, you expose them as elements you can program in server-based code.
    it is really easy, just add runat tag to the control and when you access there value to server side you need to use '.value' instead of '.Text'
    https://msdn.microsoft.com/en-us/library/s7csdtts.aspx

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #768102
    Hi Arvind

    before

    <input type="text" placeholder="Username" id ="txtid" runat="server">
    <input type="password" id ="txtpass" runat="server" placeholder="Password" />

    <span class="state" id ="btnlogin" runat="server">Log in</span>

    after

    <input type="text" placeholder="Username" id ="txtid" runat="server">
    <input type="password" id ="txtpass" runat="server" placeholder="Password" /> 
    <asp:Button ID="Button1" runat="server" Text="Button" />

    wds
    blackcaps

  • #768105
    thankss sir ji


  • Sign In to post your comments
    Submit New Thread
    Return to Return to Discussion Forum