Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

In my project, there is button to add specific topic to favorite,
when user press the button it connect to database and add specific topic to favorites for the User.

But i want to do it without postback,

So, can i used Client Callback although i need to connect to database,
if yes how to do that

or i must use AJAX ??
Posted

Have a look at below link, which covers use of "ICallBackEventHadnler" and Ajax using Jquery.

Simplifying Asp.Net Core Ajax[^]
 
Share this answer
 
Hi,
You can use ajax for this purpose you need to add Jquery library.
after it you can modify following code lines according to your requirements.
$.ajax({
type:
"POST",
url:
"AjaxCalls.aspx?functionName=addfavourite",
data:
'userID=\''+userID+ '\'&categoryID='+ selecttedategoryId ,
success: onSuccsess
});
}
function onSuccsess(result) {
finnd control ans show result
}
and on ajaxcalls.aspx page:

Ad this code in page_load event
Response.Expires = -1; //required to keep the page from being un cached on the client's browser
string switch_on = Request.QueryString["functionName"].ToLower();
switch (switch_on)
{
case "konter":
string userID= Request.Form["userID"];
string categoryID = Request.Form["categoryID"];
//insert command for this data
ResponseHandling("data saved successfully");
}


//Create function which handle ajax response.
private void ResponseHandling(string result)
{
Response.Clear(); //clears the existing HTML
Response.ContentType = "text/plain"; //change content type
Response.Write(result);//Send back the fetched value to calling function.
Response.End();
}

Thanks
Mahessh K. Sharma
http://www.helpondesk.blogspot.com
 
Share this answer
 
v2
Comments
MrLonely_2 24-Jul-11 7:02am    
Thank but i want an example of AJAX for how to connect to Database if it possible
If you donot want to use ajax but your page is work like ajax update panel you use ICallbackEventHandler interface.

how use icallbackevnethandler is view following site:-
http://msdn.microsoft.com/en-us/library/system.web.ui.icallbackeventhandler.aspx
http://www.codeproject.com/KB/aspnet/ICallbackEventHandler.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900