Thursday, April 10, 2008

Accessing server event using Ajax

Step:1

Install system.web.extension and ajax tools
Install ajax.dll in your system all add in reference of the project.

step:2
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>

step:3
Write javascript

<script language="javascript" type="text/javascript">
function Getconfirm()
{
var con=confirm("Are sure want to delete this");
var test;
if(con==false)
{
alert(Bala.Getvalue().value);
}
else
{
alert(Bala.Getvalue1().value);
}
}
</script>

step 4:
in c# page


public partial class Bala : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(Bala));
//btnsubmit.Attributes.Add("onclick", "Getconfirm();");
}
[Ajax.AjaxMethod()]
public string Getvalue()
{
return "bala";

}
[Ajax.AjaxMethod()]
public string Getvalue1()
{
return "bala1";

}
}