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

I have One Question....

Suppose, I have one Website.
In this, there is one page like Page1.aspx
Now Another page is Page2.aspx

Page2.aspx contain one function in page load event.

Now, I want to fire request through java script from Page1.aspx on Page2.aspx and execute that function, and that function should return any value to Page1.aspx through that request.

How can it possible ????????

Anybody can help me?

Thanks,
Mahesh Patel
Posted

1 solution

You can do this by Ajax.

Add reference of “jquery-1.4.1.min.js” or ”jquery-1.5.1.min.js” in your .aspx page.

In below code Javascript function "JqueryAjaxExample" will call Page Load Of Page2.aspx.

Javascript function "JqueryAjaxExampleResponse" will invoke when response will come back from Page2.aspx.

JavaScript
<script language="javascript" type="text/javascript">

     function JqueryAjaxExample() {
         $.ajax({
            type: "GET",
            url: "Page2.aspx",
            success: function (ReturnValue) {
                JqueryAjaxExampleResponse(ReturnValue);
            }
        });
    }
 
    function JqueryAjaxExampleResponse(ReturnValue) {
        alert(ReturnValue);
    }
</script>



Then write your return value to Response in your function as below.

C#
//Page Load of Page2.aspx
protected void Page_Load(object sender, EventArgs e)
{
    ReturnValueFunction();
}

private void ReturnValueFunction()
{
    string ReturnValue = "SomeThing";
    Response.Clear();
    Response.Write(ReturnValue);
    Response.End();
}
 
Share this answer
 
v4
Comments
Mr. Mahesh Patel 12-Jul-11 9:38am    
Thanks, It is working
RaisKazi 13-Jul-11 1:12am    
Perfect. Cheers !!!

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