I Want call web method from json,but web method does not call from json,when using update panel in form.I have to use update panel.
Here is my code of client side
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSave]").bind("click", function () {
var event1 = {};
event1.EventDate = $("[id*=txtEventDt]").val();
event1.Description = $("[id*=txtEventDesc]").val();
$.ajax({
type: "POST",
url: "Default3.aspx/SaveEvent",
data: '{event1: ' + JSON.stringify(event1) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$find("mpe").hide();
clear();
__doPostBack('hdText', 'JavaScript');
}
});
return false;
});
});
function clear() {
$("#txtEventDt").val("");
$("#txtEventDesc").val("");
}
</script>
Server Side Code
[WebMethod]
[ScriptMethod]
public static void SaveEvent(Event event1)
{
try
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Event VALUES(@EventDate, @Description)"))
{
cmd.CommandType = CommandType.Text;
Default3 obj = new Default3();
string eventdate=obj.changeYYYYMMDD(event1.EventDate.ToString());
cmd.Parameters.AddWithValue("@EventDate", eventdate);
cmd.Parameters.AddWithValue("@Description", event1.Description);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
catch (Exception ex)
{
}
}
Now the postback part
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation("hdText", "JavaScript");
base.Render(writer);
}
protected void hdText_Click(object sender, EventArgs e)
{
}
What I have tried:
I have tried by using postback from client side.
Any help will be very appreciated.
Please.... have a reply