saksham
saksham

Reputation: 81

Unable to detect button click in Asp.Net

I am very new to asp.net and c# and haven't written anything in the language till now. So, I am unable to detect a button click.

Here is my code:-

contact.aspx

<%@ Page Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="contact.aspx.cs" Inherits="contact" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<title>Sugarsnooper | Contact Us</title>
<meta name="keyword" content=""/>
<meta name="Description" content=""/>
<meta name="key-phrases" content=""/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<section class="content-page"><div class="container"><div class="row">
<div class="col-md-12"><h1>Contact Us</h1></div>
<div class="col-md-8">
<h4>Enquiry Form</h4>
<form id="form1" runat="server">
<div class="col-lg-12 form-group">
        <div class="row">
        <input name="name" runat="server" type="text" id="name2" class="form-control" placeholder="Enter Your Name">
        </div>
      </div>
<div class="col-lg-12 form-group">
        <div class="row">
        <input name="website" runat="server" type="text" id="cont2" class="form-control" placeholder="Enter Mobile Number">
        </div>
      </div>
<div class="col-lg-12 form-group">
        <div class="row">
       <input name="email" runat="server" type="text" id="email3" class="form-control" placeholder="Enter Your Email ID">

        </div>
      </div>
<div class="col-lg-12 form-group">
        <div class="row">
        <textarea name="message" runat="server" id="msg2" class="form-control" placeholder="Enter Your Message.." rows="6"></textarea>
        </div>
      </div>
<div class="col-lg-12 form-group">
        <div class="row">
          <input type="button" runat="server" value="Send" id="enquiry_post" onClick="enquiry_post_click" class="btn btn-primary"> 
        </div>
           <asp:Label ID="Label1" runat="server" Text="User Name"/>
      </div></form>
</div>
<div class="col-md-4"><h4>Contact Info</h4>
<table class="table">
<tr>
<td>Email</td>
<td><a href="mailto:[email protected]">[email protected]</a></td>
</tr>
<tr>
<td>Helpline No.</td>
<td>xxx xxx xxxx</td>
</tr>
</table>
</div>
</div></div></section>
</asp:Content>

contact.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class contact : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack){
    //Label1.Text = ""; 
        }
    }

    protected void enquiry_post_click(object sender, EventArgs e){

    Label1.Text = "Hi";

    }

}

Can anyone point out my error? Note:- I have seen other questions but can't seem to figure out what I am doing wrong, so don't point to another question.

Thanks in advance

Upvotes: 1

Views: 140

Answers (1)

fubo
fubo

Reputation: 45947

Replace

<input type="button" runat="server" value="Send" id="enquiry_post" 
       onClick="enquiry_post_click" class="btn btn-primary"> 

with

<asp:Button runat="server" Text="Send" ID="enquiry_post" 
     OnClick="enquiry_post_click" CssClass="btn btn-primary"/>

or

<input type="submit" class="btn btn-primary" id="enquiry_post" value="Send"             
       runat="server" onserverclick="enquiry_post_click"/>

Upvotes: 2

Related Questions