client side script, then server side

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mortar

    client side script, then server side

    i have a server side button which 1st needs to run some client side
    script for form checking. I got this working from the attributes
    thing.

    Then, if all is valid client side, i need to call the server side
    function for the button. I can't just do a submit because that won't
    call the server function. Anyone know how to do this?
  • darrel

    #2
    Re: client side script, then server side

    > i have a server side button which 1st needs to run some client side[color=blue]
    > script for form checking. I got this working from the attributes
    > thing.
    >
    > Then, if all is valid client side, i need to call the server side
    > function for the button. I can't just do a submit because that won't
    > call the server function. Anyone know how to do this?[/color]

    It sounds like you have a form, and, if the form is valid, you want
    something to happen, correct?

    If so, in the button click function, you'd do something like this:

    page.validate

    if page.isvalid then...
    do your thing
    else
    don't do it
    end if

    -Darrel


    Comment

    • Steve C. Orr [MVP, MCSD]

      #3
      Re: client side script, then server side

      You might want to use the built in ASP.NET validation controls, since they
      provide this kind of functionality.

      If your needs are modest, the code below may get you started:

      This server side code uses javascript to display a confirmation message.
      myDeleteButton. Attributes.Add( "onclick", _
      "return confirm('Are you sure you want to delete?');")

      In this example, the Delete button will post back only if the person
      confirms they want to delete. Otherwise your server code is never called in
      response to the button click.

      --
      I hope this helps,
      Steve C. Orr, MCSD, MVP



      "Mortar" <a@b.com> wrote in message
      news:41f58784.2 7798187@nntp.br oadband.rogers. com...[color=blue]
      >i have a server side button which 1st needs to run some client side
      > script for form checking. I got this working from the attributes
      > thing.
      >
      > Then, if all is valid client side, i need to call the server side
      > function for the button. I can't just do a submit because that won't
      > call the server function. Anyone know how to do this?[/color]


      Comment

      • Ryan Trudelle-Schwarz

        #4
        Re: client side script, then server side

        > i have a server side button which 1st needs to run some client side[color=blue]
        > script for form checking. I got this working from the attributes
        > thing.
        >
        > Then, if all is valid client side, i need to call the server side
        > function for the button. I can't just do a submit because that won't
        > call the server function. Anyone know how to do this?[/color]

        Assuming your control like so:

        <asp:button id="someButton " runat="server" />

        add an onclick attribute like: "return isValid();"
        (so the output should be <inut type="submit" id="someButton " onclick="return
        isValid();" />)

        and define a function like:
        "function isValid()
        {
        if(something is valid)
        return true;
        else
        return false;
        }"

        when you return false from the isValid, the click event is aborted so the
        form will not submit. If you return true, the event will continue processing
        and the form will be submitted.

        Comment

        • Mortar

          #5
          Re: client side script, then server side


          awesome! thanks guys.


          On Mon, 24 Jan 2005 23:43:55 GMT, a@b.com (Mortar) wrote:
          [color=blue]
          >i have a server side button which 1st needs to run some client side
          >script for form checking. I got this working from the attributes
          >thing.
          >
          >Then, if all is valid client side, i need to call the server side
          >function for the button. I can't just do a submit because that won't
          >call the server function. Anyone know how to do this?[/color]

          Comment

          Working...