Execute InsertQuery command from SqlDataSource in JavaScript
I am using ASP.NET
开发者_运维技巧If I want to execute my Insert command from my SqlDataSource in my code behind I would do this.
SqlDataSource1.Insert()
But how would I be able to do this in JavaScript?
<script type='text/javascript' language="javascript">
function valSubmit() {
//Need to call the Insert Command here!
}
</script>
OR
Where in my code behind can I place the Insert() command to make sure only after my valSubmit() function in JavaScript have executed it will then execute the Insert Command?
Create a Web Handler that will invoke the Insert
method and call this handler using your preferred AJAX method.
Create Ajax method Example of Ajax method
$.ajax({
type: POST,
url: url,
data: data,
success: success,
dataType: dataType
});
function success()
{
alert(data saved);
}
URL : a new page for example ajax.aspx.On this page load you can write your method for insertion.
Data : Parameters, These will be accessed using Request.Querystring
and call server methods which are used for insertion or any other operation.
精彩评论