0

I am a newbie to ASP.NET. i wish to invoke a server side event/function on a client click, without refreshing the page. I tried ajax,__dopostback etc... but failed miserably.. may be because of my less knowledge in ASP

Can anyone help me pls

$.ajax({

                             type:"POST",
                               url:"projects.aspx/slides",
                               data: "{'value':''}",
                              contentType:"application/json;charset=utf-8",
                               dataType:"json",

                              //cache:false,
                               success:function(data){
                                   alert("OK");
                                  alert(data.d);
                               },
                               error:function(XMLHttpRequest,textStatus,errorThrown)
                               {
                                   alert(textStatus);
                               }

                           });

This is my ajax code.. Is there any problem with this??

3
  • I don't see a reason for the downvotes, this guy admits he's new! He might have tried AJAX the wrong way! Commented Jan 17, 2013 at 6:54
  • if you have tried something, place it here the code Commented Jan 17, 2013 at 7:12
  • the ajax i placed above.... projects.aspx is the same page where the script runs... the method slides is in it's cs page Commented Jan 17, 2013 at 10:11

2 Answers 2

1

ASP.NET runs server side. So it can't invoke server methods. You could use AJAX to grab data, or make a REST web service to manipulate the server which you can then call from javascript. One thing potentially worth investigating is SignalR. It's very easy to use and involves a constant dialog between the server and all clients that is completely set up for you.

I can't really help you any more than that, because you haven't actually asked a question.

Sign up to request clarification or add additional context in comments.

3 Comments

I have a jQuery slide in my webpage, that contains images. Obviously there is a next arrow and prev arrow, which is dynamically generating by the script. So for each click of next or prev button i have to increment the value of a hidden field and rebind the repeater in reference to the value in hidden field. So my problem is i can only have a click event of next and prev in jQuery. and the code for rebinding the repeater is in my cs page.. How can i animate the slide and rebind the repeater at the same time....
You can't. Or at the very least shouldn't. I'm sure there's some horrible, hacky approach to this using repeated requests to the server, but this is a thing that should be done entirely in Javascript. It would be both neater and easier.
But how can i rebind the repeater using javascript?
0

Why dont you try adding those functionality in separate asp page and then if in case you need to load those html response in current asp page you can try

$('.btn').bind('click',function(){

        $('.div_in_which_to_load_response').load('./webservices/your_functionality_page.asp'{"data1": dummy1});
                return false;  


            });

1 Comment

How can I change the value of the hidden field in the current ASP page? My method to cal actually contains the following two lines HiddenField1.Value =Convert.ToString(Convert.ToInt16(HiddenField1.Value) + 1); bindrepeater();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.