简体   繁体   中英

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

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" />

Try adding the AutoPostBack property to your button.

 AutoPostBack = "true"

Also, make sure your controls are within a

<form>

element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM