I have the following codes :
<input id="pwd" name="txtPwd" />
<input type="submit" value="Save" />
I need to disable the submit button when the pwd input is null
How can I do it without JQuery?
I have the following codes :
<input id="pwd" name="txtPwd" />
<input type="submit" value="Save" />
I need to disable the submit button when the pwd input is null
How can I do it without JQuery?
From what i got from your question , you want to change the submit button from disabled to enabled when there is a value in the password field right?
Well if you have a "required" validation attached to the password field .i.e bound with a model then the form will not submit, since the validation will fail and halt the form submission. Still, that's using jQuery validation in the background automatically.
Html Code:
<html>
<body>
<form runat="server" action="">
<asp:ScriptManager ID="scriptmanager" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txtPassword" runat="server" AutoPostBack="true" Text=""></asp:TextBox>
<asp:UpdatePanel ID="updatePanel3" runat="server">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Enabled="false" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtPassword" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
C#Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
else
{
if (txtPassword.Text != "" && txtPassword != null)
{
btnSubmit.Enabled = true;
}
else
{
btnSubmit.Enabled = false;
}
}
}
Example of disabling button without jquery, but using javascript
<html>
<head></head>
<body>
<div>
<input id="pwd" name="txtPwd" />
<input type="submit" id="button" value="Save" />
</div>
<script type="text/javascript">
var element = document.getElementById("button");
element.setAttribute("disabled", "disabled");
</script>
</body>
</html>
Or you can set disabled attribute on server side.
If the only problem you have is cannot use JQuery, then you can use Javascript.
Set the submit button to be as disabled, and use javascript to change the status of the button when the pwd field is entered with value. You can even add validation on the format of the password you want user to enter.
If you cannot use javascript, then you have to do the second option "testCoder" suggested that control this behavior from server side.