简体   繁体   English

Ajax删除我的JavaScript所做的任何更改

[英]Ajax removes any changes made my javascript

Using 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. 我使用ajax导致OnTextChangedEvent发生,这之前有一些Javascript会对输入字段进行检查以进行验证,并根据其是否有效输出一些文本。 The Ajax I run resets the changes made by my javascript. 我运行的Ajax重置了我的JavaScript所做的更改。 It all happens in this order: 一切按此顺序进行:

Javascript fires! Javascript触发!

Text changes show 文字变更显示

Ajax fires! 阿贾克斯开火!

Text changes reset 文字变更重设

The ajax partial autopostback is contained in an update panel. Ajax部分自动回发包含在更新面板中。 Without giving any code away is there anyone who has an idea of a way to stop the javascript changes resetting? 在不提供任何代码的情况下,是否有人想出一种方法来阻止javascript更改重置?

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. 文本更改是在DOM模型中进行的,不会传输到服务器。 If the ajax fires it will override the changes in the DOM made by javascript. 如果ajax触发,它将覆盖javascript对DOM所做的更改。

Solution is to transmit the validation-texts to the server and to add them again via ajax. 解决方案是将验证文本传输到服务器,然后通过ajax再次添加它们。

An UpdatePanel completely replaces the contents of the update panel on an update . UpdatePanel完全替换更新中更新面板的内容
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 在您的Page或MasterPage中,放入以下脚本

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当我在 DataGrid 中做了一些更改时,我的 ObservableCollection 没有任何更改? - Why I don't have any changes in my ObservableCollection when I have made some in my DataGrid? 有什么工具可以监视应用程序所做的更改? - Any tools to monitor the changes made by an application? 如果调试后进行了任何更改,则不会刷新Crystal报表字段 - Crystal report fields are not refreshed if any changes made after debugging 如何在可观察集合的 UI 中立即反映任何添加、删除、字段更改 - How to reflect any Adds, Removes, field changes immediately in the UI for Observable Collection NHibernate 如何跟踪对我的实体中的字段所做的更改? - How NHibernate track changes made to the fields in my entity? 为什么对数据库进行更改时我的绑定没有更新? - Why is my Binding not updating when changes are made to database? 我在 Blazor Wasm 中所做的解决方案更改不会为我加载 - The changes of my solution made in Blazor Wasm do not load for me 为什么我的媒体资源不知道直接对数据库所做的更改 - Why isn't my property aware of changes made directly to the database C#/ WPF:对剪贴板进行任何更改时触发的任何事件? - C#/WPF: Any event that triggers when any changes are made to clipboard? FireFox删除了我的尾随“ 0” - FireFox Removes My Trailing '0'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM