Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Java script
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 12-Jul-11 3:59am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
 
 
<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.
 
 
 
//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();
}
 
  Permalink  
v4
Comments
Mr. MAHESHKUMAR at 12-Jul-11 9:38am
   
Thanks, It is working
RaisKazi at 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)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 12 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100