[英]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.