gpt4 book ai didi

javascript - 如何等待 ASP.NET Multiview 通过 PostBack 更改其 ActiveViewIndex

转载 作者:行者123 更新时间:2023-11-30 06:46:53 24 4
gpt4 key购买 nike

我在 ASP.NET 3.5 中工作,使用 VB.NET 作为我的服务器端语言。我通过 jQuery 1.5.2 使用 JavaScript 作为我的客户端语言。我正在尝试使用此页面进行原型(prototype)/命名空间设置。此页面是使用 MultiView 的自定义登录页面。我有一个策略登录 View 和一个忘记密码 View 。我将 ActiveViewIndex 存储在名为 currentView 的隐藏字段中。

我在这个项目中使用部分回发和 UpdatePanel,并且 JS 没有在部分回发上刷新。

就是说,我需要一种方法来等待 ActiveViewIndex 在服务器端发生更改,以便我可以调用相应 View 的 init() 函数。这可能吗?

我的客户端代码:

全局 JS


var page = 
{
currentView : getContentElement( "currentView" ),

init : function ()
{
log( "initializing page" );

if ( this.currentView === "forgotpassword" ) { forgotPassword.init(); }
else { policyLogon.init(); }
}
};

page.init();

策略登录 View JS


var policyLogon = 
{
panel : getContentElement( "pnlLogonInfo", "div" ),
submitButton : getContentElement( "btnLogon", this.panel ),
textInputs : $( "input[ type=text ]", this.panel ),
policyNumber : getContentElement( "txtPolicyNumber", this.textInputs ),
policyNumberError : getContentElement( "lblPolicyNumberError", this.panel ),
password : getContentElement( "txtPassword", this.textInputs ),
passwordError : getContentElement( "lblPasswordError", this.panel ),
forgotPasswordLink : getContentElement( "lbtnForgotPassword", this.panel ),

init : function ()
{
log( "initializing policy logon" );

var that = this;

// Other event handlers created here [redacted to keep example code short].

that.forgotPasswordLink.on("click", function ()
{
// Code to wait for PostBack should go here.

page.init();
});

that.policyNumber.focus();
}
};

忘记密码查看JS


var forgotPassword = 
{

// Local vars, set up the same way as Policy Logon, just different elements.
// [redacted to keep example code short]

init : function ()
{
log( "initializing forgot password" );

var that = this;

// Other event handlers created here [redacted to keep example code short].

that.policyNumber.focus();
}
};


作为对什么是 getContentElement() 问题的先发制人的打击,getContentElement() 是我必须创建的函数,因为嵌套母版页中的元素必须根据他们使用的母版页的不同而不同。它看起来像这样:

function getContentElement ( id, context ) 
{
var publicPrefix = csMasterPrefix + csContentPrefix,
securePrefix = cpMasterPrefix + publicPrefix + cpContentPrefix,
publicId = "#" + publicPrefix + id,
secureId = "#" + securePrefix + id;

return ( context )
? ( isSecurePage ) ? $( secureId, context ) : $( publicId, context )
: ( isSecurePage ) ? $( secureId ) : $( publicId );
}

最佳答案

与其直接调用 page.init(),不如将其绑定(bind)到 body 的 onLoad even。

$(document).ready() { page.init() }

此时,DOM已经从服务器返回,ActiveIndexItem也已经设置。

关于javascript - 如何等待 ASP.NET Multiview 通过 PostBack 更改其 ActiveViewIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5783413/

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