gpt4 book ai didi

c# - 防止来自 __doPostBack 的完整回发

转载 作者:行者123 更新时间:2023-11-30 22:36:41 24 4
gpt4 key购买 nike

我有一个包含以下内容的内容页面...

  1. UpdatePanel1 - containing Error Display Divs
    contains update triggers for both buttons
  2. UpdatePanel2 - containing process 1 with an asp:button
  3. updatePanel3 - containing process 2 with an asp:button
  4. JavaScript that presents the user with a Popup confirm Jquery Messagebox based on the process they are executing.

UpdatePanel 2 或 3 根据用户从菜单选项中的选择变为可见。

selecting menu item 2 will display this page shown with an error message

当我单击一个按钮时,消息框会弹出,并且会使用来自消息框响应的 __doPostback 正确处理页面,并且该页面会执行完整的回发。

我宁愿页面执行部分回发和它所拥有的内容,并在出现错误时显示错误显示 Divs。如有任何帮助,我们将不胜感激。

按钮没什么特别的

<asp:Button ID="ResetSomething" runat="server" Text="ResetSomething" Width="275px" />

这是内容页面脚本 block

    <script type="text/javascript" language="javascript">
<!--
function pageLoad() {
setform();

};

function setform() {
var reset1_button = $('input[id*=ResetSomething]');
var reset2_button = $('input[id*=ResetSomethingElse]');

reset1_button.click(function() {
var element = $(this);
$.prompt('Message1', { show: 'slideDown', buttons: { Ok: true, Cancel: false },
submit: function(v, m, f) { submit_reset_callback(v, m, element); }
});
return (false);
});

var submit_reset_callback = function(result, messages, element) {
if (result) { __doPostBack("ResetSomething");}
return (false);
};

reset2_button.click(function() {
var element = $(this);
$.prompt('Message2', { show: 'slideDown', buttons: { Ok: true, Cancel: false },
submit: function(v, m, f) { submit_update_callback(v, m, element); }
});
return (false);
});

var submit_update_callback = function(result, messages, element) {
if (result) { __doPostBack("ResetSomethingElse"); }
return (false);
};
};
-->
</script>

这是 OnInit 背后的代码:

    protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.PreLoad += (sender, args) =>
{

this.ClientScript.GetPostBackEventReference(this, "arg");

if (!IsPostBack) { return; }

string __targetaction = this.Request["__EVENTTARGET"];
string __args = this.Request["__EVENTARGUMENT"];

if (string.IsNullOrEmpty(__args)) return;

if (__targetaction == "ResetSomething")
{
ResetSomething();
}
if (__targetaction == "ResetSomethingElse")
{
ResetSomethingElse();
}
this.upnlNotifications.Update();
};
}

最佳答案

定义下面的函数并将您的 __doPostBack 调用替换为 doPostBackAsync(controlId, null)

function doPostBackAsync(eventName, eventArgs) {
var prm = Sys.WebForms.PageRequestManager.getInstance();

if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
prm._asyncPostBackControlIDs.push(eventName);
}

if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
prm._asyncPostBackControlClientIDs.push(eventName);
}

__doPostBack(eventName, eventArgs);
}

关于c# - 防止来自 __doPostBack 的完整回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6874461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com