I am trying to check if the specific value exist in the data base that is working perfect but what i want is
- I want to call a C# function from JavaScript
- as now in my code after JavaScript clicks button it response but page also refreshes i don't Want page refresh to be happen
better way to call C# function with out using button from javascript
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 button
<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()