提问人:issam merheb 提问时间:10/9/2018 最后编辑:Basissam merheb 更新时间:10/26/2018 访问量:85
Asp Button 不起作用,也不执行后面的功能
Asp Button doesn't work and doesn't execute function behind
问:
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赞
Seano666
10/26/2018
#1
尝试将 AutoPostBack 属性添加到按钮。
AutoPostBack = "true"
此外,请确保您的控件位于
<form>
元素。
评论
asp:button
searchhosp