Thursday, 12 December 2013
jQuery Ajax Submit Form without Page Refresh using JSON in Asp.Net
jQuery Submit a form without postback
After completion of aspx page design add the following namespaces in code behind
C# Code
using System;using System.Data;using System.Data.SqlClient;using System.Web.Services;
After that write the following code in code behind
protected void Page_Load(object sender, EventArgs e){}[WebMethod]public static string InsertData(string username, string subj, string desc){string msg = string.Empty;using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")){using (SqlCommand cmd = new SqlCommand("insert into TEMP_User(Name,Subject,Description) VALUES(@name,@subject,@desc)", con)){con.Open();cmd.Parameters.AddWithValue("@name", username);cmd.Parameters.AddWithValue("@subject", subj);cmd.Parameters.AddWithValue("@desc", desc);int i= cmd.ExecuteNonQuery();con.Close();if (i == 1){msg = "true";}else{msg = "false";}}}return msg;}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment