【发布时间】:2015-12-22 10:05:04
【问题描述】:
我正在尝试检查数据库中是否存在运行完美但我想要的是特定值
- 我想从 JavaScript 调用 C# 函数
- 现在在我的代码中 JavaScript 单击按钮后它会响应但 页面也会刷新我不希望页面刷新发生
-
在不使用 javascript 按钮的情况下调用 C# 函数的更好方法
protected void Check_exam_id(object sender, EventArgs e) { string DDSelected_Class = DD_class.SelectedValue;// store it in some variable; string DD__Method = DD_Method.SelectedValue;// store it in some variable; if (DD__Method == "THEORY") { using (MySqlConnection myConnection = new MySqlConnection(constr)) { string oString = "Select * from score_master WHERE Class=@DDSelected_Class "; MySqlCommand oCmd = new MySqlCommand(oString, myConnection); oCmd.Parameters.AddWithValue("@DDSelected_Class", DDSelected_Class); myConnection.Open(); using (MySqlDataReader oReader = oCmd.ExecuteReader()) { if (oReader == null || !oReader.HasRows) { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('No Student Found')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert2", "alert('Exist')", true); myConnection.Close(); } } } } }
asp 按钮
<asp:Button runat="server" id="Check_examid" AutoPostback = "false" onclick='Check_exam_id' style=" display:none; float: right; width: 22%; height: 41px; text-align: center; background: #EAEAEA; border: none; border-color: #EAEAEA; margin-top: 2%;" Text="Submit"></asp:Button>
Javascript
document.getElementById("BodyHolder_Check_examid").click()
【问题讨论】:
-
使用 jquery ajax 对您的方法进行 ajax 调用。
-
@RahulSingh 我不确定如果你给我一个更有帮助的例子
标签: javascript c# jquery asp.net