|
-
Jan 4th, 2009, 08:48 PM
#1
Thread Starter
Addicted Member
[2005] Enabling/Disabling Buttons
Ok, here's the situation. I have an .aspx page with two buttons.
Based on the actions going on in the form, one of the two buttons will be invisible.
In my VB code-behind, I set an attribute for each button on the form so that when clicked, the button will become disabled while the user is redirected to another page.
This works fine and good, except for the validation. For instance, if someone does not type in a first name, they will get an error message saying it's a required field. However, the button is still disabled.
To get around this problem, I just set the "onKeyUp" attribute of the text box to re-enable the button. Problem solved right? Wrong.
Now I have an even bigger problem. ASP.Net will only let me specify the "onKeyUp" event once in a tag. So, if the "Submit" button raises client validation, I can type in a valid value and the button is re-enabled. However, if the submit button isn't shown, since the user is in edit mode, the "Edit" remains disabled even if a valid value is in the textbox, because I've only been able to set the onKeyUp for the "Submit" button.
Anyone know how I can overcome this obstacle? It's really frustrating. I'm pretty sure I will have to come up with a Javascript function of some sort, and pass in the button I want re-enabled, instead of just defining it explicitly, but I'm in desperate need of help.
Oh, and mods feel free to move this to the Javascript forum if necessary. I didn't know whether to put it in the ASP.Net forum or Javascript.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Jan 4th, 2009, 10:00 PM
#2
Fanatic Member
Re: [2005] Enabling/Disabling Buttons
use a asp.net validation control control
-
Jan 5th, 2009, 05:18 AM
#3
Frenzied Member
Re: [2005] Enabling/Disabling Buttons
Hi!
I would create a custom validation contorl. There you can specify exactly what will happen both on the client and server. It should solve your problem and is not very difficult to implement. If you need sample code I can provide it...
kind regards
Henrik
-
Jan 5th, 2009, 07:17 AM
#4
Thread Starter
Addicted Member
Re: [2005] Enabling/Disabling Buttons
MrNorth, I would very much appreciate some sample code.
If my post helped you, please rate it!
Languages: VB/ASP.NET 2005, C# 2008,VB6
Databases: Oracle (knowledge not currently in use), DB2
FROM Customers
WHERE We_Know_What_We_Want <> DB.Null
SELECT *
0 rows returned
-
Jan 5th, 2009, 09:35 AM
#5
Frenzied Member
Re: [2005] Enabling/Disabling Buttons
Hi!
Ok here is the code I used for checking number of characters in a textarea.
Server:
Code:
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
args.IsValid = args.Value.Length <= 1000
End Sub
And here is the client code:
Code:
<script language="javascript" type="text/javascript">
function IsLengthValid(source, args)
{
args.IsValid = args.Value.length <=1000;
}
</script>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtDescription"
CssClass="error" Display="Dynamic" ErrorMessage="Length can be no greater than 1000 characters"
SetFocusOnError="True" ClientValidationFunction="IsLengthValid"></asp:CustomValidator>
As u can see its pretty straight forward. Just implement the servervalidate eventhandler on teh server and then write a nifty javascript for the client part. It uses the javascript first, and if the user disabled scripting, it runs the server validation instead. With this u can implement different validations for server/client. I find this very handy and flexible.
Good luck
Henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|