开发者

Ajax removes any changes made my javascript

开发者 https://www.devze.com 2023-04-12 11:31 出处:网络
Usin开发者_C百科g ajax I am causing an OnTextChangedEvent before this happens there is some Javascript that performs a check on the input field for validation and outputs some text based on whether it

Usin开发者_C百科g ajax I am causing an OnTextChangedEvent before this happens there is some Javascript that performs a check on the input field for validation and outputs some text based on whether it is valid or not. The Ajax I run resets the changes made by my javascript. It all happens in this order:

Javascript fires!

Text changes show

Ajax fires!

Text changes reset

The ajax partial autopostback is contained in an update panel. Without giving any code away is there anyone who has an idea of a way to stop the javascript changes resetting?

Over the day I will add code as I find time. Thought I would get the question up atleast. Thanks in advanced.


The Text changes are made in the DOM-Model and are not transmitted to the server. If the ajax fires it will override the changes in the DOM made by javascript.

Solution is to transmit the validation-texts to the server and to add them again via ajax.


An UpdatePanel completely replaces the contents of the update panel on an update.
This means that those events you subscribed to are no longer subscribed because there are new elements in that update panel.
Full answer here

In your Page or MasterPage, put the following script

<script type="text/javascript">
  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

  function EndRequestHandler(sender, args)
  {
    Validate(); //method that performs check on input field
  }   
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消