当用户点击登录按钮时,我想调用login.ascx文件中的javascript函数。
以下是login.ascx代码的代码:
<div class="dnnFormItem">
<asp:label id="lblLogin" runat="server" AssociatedControlID="cmdLogin" CssClass="dnnFormLabel" />
<asp:LinkButton id="cmdLogin" resourcekey="cmdLogin" cssclass="dnnPrimaryAction" text="Login" runat="server"/>
<script type="text/javascript">
/*globals jQuery, window, Sys */
(function ($, Sys) {
function setUpLogin() {
var actionLinks = $("a[id$=cmdLogin]");
actionLinks.click(function () {
if ($(this).hasClass("dnnDisabledAction")) {
return false;
}
actionLinks.addClass("dnnDisabledAction");
});
}
$(document).ready(function () {
setUpLogin();
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
setUpLogin();
});
});
}(jQuery, window.Sys));
以下是login.ascx中的javascript代码,我想在用户点击登录按钮时调用它。
function myTestFun() {
//var _currentUser =
// DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
var userName = '<%=username%>';
var fname = '<%=firstnm%>';
var userinfo= {
"Usr_Username": userName,
"Usr_Email": "",
"Usr_FirstName": fname
};
localStorage.setItem('GoDashProUser', JSON.stringify(GoDashProUser));
}
</script>
以下是使用C#的代码隐藏文件:
private void OnLoginClick(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
if (loginStatus == UserLoginStatus.LOGIN_USERNOTAPPROVED)
{
message = "UserNotAuthorized";
}
else
{
authenticated = (loginStatus !=UserLoginStatus.LOGIN_FAILURE);
}
//Raise UserAuthenticated Event
var eventArgs = new UserAuthenticatedEventArgs(objUser, txtUsername.Text, loginStatus, "DNN")
{
Authenticated = authenticated,
Message = message,
};
//string script = "<script type=\"text/javascript\"> myTestFun(); </script>";
//ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", script);
// cs.RegisterStartupScript(GetType(), "myTestFun", "myTestFun();", true);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "myTestFun()", true);
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), UniqueID, "myTestFun();", true);
firstnm = objUser.FirstName;
OnUserAuthenticated(eventArgs);
}
}
我已经尝试了大多数可能的选项来调用javascript函数,但它不会调用。我想调用javascript函数将数据保存到本地存储中,并且还想传递userinfo的值。
请告诉我一些方法。谢谢。
答案 0 :(得分:0)
<asp:LinkButton OnClientClick="myTestFun()" id="cmdLogin" resourcekey="cmdLogin" cssclass="dnnPrimaryAction" text="Login" runat="server"/>