0

I call another page with an id, which returns the data based on id. I need the result value in JavaScript.

Then I need to bind the result to current page content area and display it to the user.

Initially, the user clicks one link in current page, then the id of the link should be passed to another page, and processed some function and get result from db.

I want to display the result in current page.

I am using vs2010. How can I do this?

Incognito
  • 20,537
  • 15
  • 80
  • 120
Pooja
  • 495
  • 3
  • 9
  • 25
  • possible duplicate of [call ASP.net web service from javascript client](http://stackoverflow.com/questions/7943599/call-asp-net-web-service-from-javascript-client) – Vladimir Dec 28 '11 at 06:07
  • this will help you. try this link [click here](http://www.seoasp.net/post/2008/07/16/jQuery-To-Call-ASPNET-Page-Methods-and-Web-Services.aspx) – ravidev Dec 28 '11 at 05:59

4 Answers4

0

So, you already have solved your asp.net part (you have the page, right?).

What you can do is use jquery and make an ajax call to that page and process the result. If your page returns a the information in json or xml format, it's easy to use it to upgrade your current document in the browser.

Here you will find the documentation and some samples of Jquery ajax: http://api.jquery.com/jQuery.ajax/

Hope it helps.

Ivo
  • 8,172
  • 5
  • 27
  • 42
0
function ajaxCall(id_from_your_page){
    $.ajax({
      type: "POST",
      url: '/service.asmx/your_method',
      data: { 'id', id_from_your_page },  
      dataType: "application/json; charset=utf-8",
      success: function(result){
          alert("i got your result: " + result);
      }
    });
}
hackp0int
  • 4,052
  • 8
  • 59
  • 95
0

the above code is better as you will use JQuery and POST method.

you may also like this-

function sendRequest(id) {

    var xmlObj = null;
    if(window.ActiveXObject) {
     xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
     xmlObj = new XMLHttpRequest();
    }

    if(!xmlObj) return;

    var location = "http://localhost:8080/myapplication/mypage?id="+ id;

    xmlObj.open("GET", location, true);
    xmlObj.onreadystatechange = function() {
      if(xmlObj.readyState==4 && xmlObj.status==200) {
        doSomethingWithTheResponse(xmlObj.responseText);
      }
    }
    xmlObj.send(null);
}

function doSomethingWithTheResponse(responseText) {
     // write your own code to handle the response from the page.
}

All the best :)

Acn
  • 1,010
  • 2
  • 11
  • 22
0

You can get the Id/Data from other pages or Db like this....

<asp:LinkButton runat="server" Text='<%#Eval("Title")%>'OnClick='javascript:ShowEventDetails'CommandArgument='<%#Eval("EventID").ToString()%>);'/> 

or

onclick='<%# "PopulateTicketDiv(" +Eval("SHOW_ID") + " );" %>'

ASPX:

<asp:Button ID="btnget" runat="server" Text="Create WR" onClientClick="<%# GetPopupScript() %>" /> 

Code-behind:

protected string GetPopupScript() {  
return string.Format( "javascript:popUp('popup_createWR.aspx', '{0}', '{1}')", Eval( "dvc_nm" ), Eval( "data_orgtn_yr" ) ); } 

or try this...

<asp:LinkButton ID="LinkButton5"  OnClientClick='<%# "return fun1("""  + Eval("mid") + """);"%>'  runat="server"><%#Eval("mname")%></asp:LinkButton>
RajeshKdev
  • 6,365
  • 6
  • 58
  • 80