Jan 15, 2018, 9:16 AM
Button not enable if validation is not true
Hi
I am having a problem with validation, in case the user type an invalid user or password, when the system returns from validation, the login button remains disabled even if I type other things in the user and password fields...
This is my code: ( I just build this code merging some examples )
Login.aspx
I am having a problem with validation, in case the user type an invalid user or password, when the system returns from validation, the login button remains disabled even if I type other things in the user and password fields...
This is my code: ( I just build this code merging some examples )
Login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Test1.Account.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login test</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
</head>
<script>
var invalidateLogin = function (reason) {
App.txtUsername.setValidation(reason);
App.txtPassword.setValidation(reason);
App.txtUsername.validate();
App.txtPassword.validate();
Ext.MessageBox.show({
title: 'Fail :(',
msg: reason,
buttons: Ext.MessageBox.OK,
animateTarget: 'Window1',
icon: 'Error'
});
};
var orgFormAction, orgFormTarget,
btn = null, iframe = null;
var handleClientClick = function () {
var form = App.frmPanelLogin.el.up().dom;
if (Ext.isIE) {
if (iframe == null) {
iframe = document.createElement("IFRAME");
iframe.name = "ie_login_flush";
iframe.style.display = "none";
form.appendChild(iframe);
}
if (btn == null) {
btn = document.createElement("BUTTON");
btn.type = "submit";
btn.id = "submitButton";
btn.style.display = "none";
form.appendChild(btn);
}
setForm(form, "about:blank", "ie_login_flush");
btn.click();
restoreForm(form);
}
}
var setForm = function (form, action, target) {
if (typeof orgFormAction == 'undefined') {
orgFormAction = form.action;
}
if (typeof orgFormTarget == 'undefined') {
orgFormTarget = form.target;
}
form.action = action;
form.target = target;
};
var restoreForm = function (form) {
form.action = orgFormAction;
form.target = orgFormTarget;
};
</script>
<body>
<ext:ResourceManager runat="server" />
<ext:Viewport runat="server">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Center" Pack="Center" />
</LayoutConfig>
<Items>
<ext:FormPanel
ID="frmPanelLogin"
runat="server"
Title="Login"
Width="400"
Frame="true"
BodyPadding="13"
DefaultAnchor="100%">
<Items>
<ext:TextField
ID="txtUsername"
runat="server"
AllowBlank="false"
FieldLabel="User"
Name="username"
EmptyText="User" />
<ext:TextField
ID="txtPassword"
runat="server"
AllowBlank="false"
FieldLabel="Password"
Name="password"
EmptyText="Password"
InputType="Password" />
</Items>
<Buttons>
<ext:Button
ID="btmLogin"
runat="server"
Text="Login"
Icon="Accept"
FormBind="true"
Handler="handleClientClick">
<DirectEvents>
<Click
OnEvent="Button1_Click"
Failure="invalidateLogin(result.errorMessage);"
ShowWarningOnFailure="false">
<EventMask ShowMask="true" Msg="Checking username and password" MinDelay="200" />
<ExtraParams>
<ext:Parameter Name="user" Value="App.txtUsername.value" Mode="Raw" />
<ext:Parameter Name="pass" Value="App.txtPassword.value" Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Items>
</ext:Viewport>
</body>
</html>
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test1.Account
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, DirectEventArgs e)
{
if (e.ExtraParams["user"] != "aabb" || e.ExtraParams["pass"] != "bbaa")
{
e.Success = false;
e.ErrorMessage = "User or password is invalid :(";
}
else
{
FormsAuthentication.SetAuthCookie(e.ExtraParams["user"], false);
X.Redirect("/Home.aspx");
//X.Redirect(FormsAuthentication.GetRedirectUrl(user, false));
}
}
}
}