简体   繁体   中英

asp.net and jquery

I've just started to use jquery and asp.net, bearing this in mind I was wondering if someone could help me with the following question.

say I have an ASP:Link which when clicked performs a server side function "setData()", I then have jquery to set the class of the link to selected or hide the link (using animation). the problem im having is that when you press the link the server goes and does what it has to and reloads the page, this in turn reloads the whole DOM and the stuff jquery does is deleted.

is there any way i can have both the jquery and asp.net working together without the asp.net reloading the page. I hope this makes sense. I know I can set the links cssclass to be selected from the server side but the above example is just a simple example.

There are definitely a few ways you can go about this... But, going off your description, I would say that the easiest route would be to use an update panel ( System.Web.UI.UpdatePanel ), doing a partial page postback. From there you can control the visibility of the link, panel, etc... Otherwise, look into doing partial page postback using jQuery itself (using jquery.get or jquery.post).

Anytime you issue a postback this is going to be an issue, you would need to do an ajax call to your server side method in order for things to work the way you would like. I suppose there might be a workaround in order to have postback and your jquery click, but it would be sloppy. Ajax call would be the best solution.

This article should be of a lot of help to get going on this. http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM