我在 ASP.NET 3.5 中使用 VB.NET 作为我的服务器端语言。我通过 jQuery 1.5.2 使用 JavaScript 作为我的客户端语言。我正在尝试使用此页面进行原型/命名空间设置。此页面是使用 MultiView 的自定义登录页面。我有一个策略登录视图和一个忘记密码视图。我将 ActiveViewIndex 存储在一个名为currentView
.
我在这个项目中使用带有 UpdatePanel 的 Partial Postbacks,并且 JS 不会在 Partial PostBacks 上刷新。
也就是说,我需要一种方法来等待 ActiveViewIndex 更改服务器端,以便我可以将init()
函数调用到相应的视图。这可能吗?
我的客户端代码:
全球JS
var page =
{
currentView : getContentElement( "currentView" ),
init : function ()
{
log( "initializing page" );
if ( this.currentView === "forgotpassword" ) { forgotPassword.init(); }
else { policyLogon.init(); }
}
};
page.init();
策略登录视图 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 );
}