Results 1 to 5 of 5

Thread: [2005] Enabling/Disabling Buttons

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Between Try & Catch
    Posts
    249

    [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

  2. #2

  3. #3
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Between Try & Catch
    Posts
    249

    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

  5. #5
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    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
  •  



Click Here to Expand Forum to Full Width