Asp Button doesn't work and doesn't execute function behind

95 Views Asked by At

the asp button doesn't fire and doesn't execute c# code behind there is the code what is the cause of this issue

protected void searchhosp(object sender, EventArgs e) {
    string cityname = city.Value;
    DataBaseConnection db  = new DataBaseConnection();
    db .disconnect();

    string sql  = "select Hospital_ID , Hospital_Name From TBL_Hospitals where City like'%"+cityname+"%'";
    SqlCommand cmd  = new SqlCommand(sql , db.connect());
    hospSelect.DataSource = cmd.ExecuteReader();
    hospSelect.DataTextField = "Hospital_Name";
    hospSelect.DataValueField = "Hospital_ID";
    hospSelect.DataBind();
    hospSelect.Items.Insert(0, "--Choose Hospital--");             
}

<input type="text" class="input2"  id="city" runat="server" > 
    <select runat="server" class="chosen" name="slct"  onchange="myFunction2();"  id="hospSelect">
</select>

<asp:Button ID="Button2" OnClick="searchhosp" CssClass="btnn" runat="server" Text="Search" />
1

There are 1 best solutions below

0
On

Try adding the AutoPostBack property to your button.

 AutoPostBack = "true"

Also, make sure your controls are within a

<form>

element.