[英]Jquery UI and ASP.NET PostBack fail after post back
I have a asp.net web forms app with update panels. 我有一个带有更新面板的asp.net网络表单应用程序。 and its also in a listview and I dont know if that matters or not.
并且它也在listview中,我不知道这是否重要。
I have the following Javascript.. 我有以下Javascript。
<script lang="javascript" type="text/javascript">
function pageLoad(sender, args)
{
$(document).ready(function () {
$('textarea.epop').live('click', test);
});
function tes(event)
{
var btn = $(this);
alert(btn.val());
$('#editortext').val(btn.val());
var dialog = $('#edialog').dialog({
modal: true,
width:'auto',
resizable: false,
buttons: {
'OK': function() {
alert($('#editortext').val());
alert(btn.val());
btn.val($('#editortext').val());
$('#editortext').val("");
$(this).dialog('close');
return false;
}
}
});
// Move the dialog back into the <form> element
dialog.parent().appendTo(jQuery("form:first"));
$('#edialog').dialog('open');
return false;
}
}
</script>
Then I have this in the html body.. 然后我在html正文中有这个。
<div id="edialog" title="Edit SQL" style="display: none">
<label for="editortext">
SQL Query:</label>
<textarea rows="20" cols="100" id="editortext" class="editortext"></textarea>
</div>
and then in one of my list items in my list view wich is inside a update panel. 然后在我的列表视图中的一个列表项中,它位于更新面板中。 I have..
我有..
<asp:TextBox ID='txtSQLQuery' CssClass="epop" TextMode="multiline" Columns="50" Rows="5" runat="server" Text='<%# Eval("SQLQuery") %>' />
code works perfect the first time with no post back. 代码在没有回发的情况下首次完美运行。 but say I change the selection, and then a auto postback happens... then the code no longer sets the text.. when you click ok.. using alerts I can see that its actually still referencing the old value and not the new current displayed value which seemed to invoke the click.
但是说我更改选择,然后发生自动回发...然后代码不再设置文本..当您单击“确定” ..使用警报时,我可以看到它实际上仍然引用旧值而不是新值显示的价值似乎可以激发点击。
At this point I am stumped.. 在这一点上,我很沮丧。
If you have your controls inside updatepanel and the update panel is set to updatemode ="condicional" you probably have to invoke updatePanel.update() from your server side code to update values. 如果您的控件位于updatepanel内部,并且更新面板设置为updatemode =“ condicional”,则可能必须从服务器端代码中调用updatePanel.update()来更新值。
Another thing that often happens is that the update panel and jquery are not best friends, so it will be better writing or initialize your code like this: 经常发生的另一件事是,更新面板和jquery不是最好的朋友,因此最好像这样编写或初始化代码:
$(document).ready(function () {
$('textarea.epop').live('click', function(e){
test();
});
});
// register again after postback's //回发后再次注册
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
$('textarea.epop').live('click', function(e){
test();
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.