asp按钮不触发,并且不执行c#代码,后面的代码是导致此问题的原因
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" />
答案 0 :(得分:0)
尝试将AutoPostBack属性添加到您的按钮。
AutoPostBack = "true"
还要确保您的控件在
内<form>
元素。