How-to? - Process Client-side AND Server-side Code Blocks With aspnet Button

Discussion in 'ASP .Net' started by Joey, Jan 3, 2006.

  1. Joey

    Joey Guest

    I have a web application with a page where user can go to upload data
    files. When they click "Upload", which is an aspnet Button, I want to
    be able to instantly hide a couple of textboxes and buttons on the
    webpage before doing the postback. This is because if I place code to
    do this in the server-side code block, it doesn't get executed until
    after the upload completes - not very useful for this scenario! And so
    I thought I would put in some client-side javascript to do the job .
    But how do I wire up the client side function to the aspnet Button? I
    need to be able to execute the client side javascript code block and
    then immediately execute the server side code block afterwards. The
    runat="server" is required for the aspnet Button, or at least that's
    what the VS2005 compiler says. So how can I accomplish this?
     
    Joey, Jan 3, 2006
    #1
    1. Advertising

  2. RE: How-to? - Process Client-side AND Server-side Code Blocks With asp

    Hi Joey,

    You can add an attribute to the button for example by overriding the page
    prerender event:
    protected override void OnPreRender(EventArgs e)
    {
    Button1.Attributes["onclick"]="alert('clicked')";
    base.OnPreRender (e);
    }
    Substitute the alert by your client script.
    Hope this helps.


    "Joey" wrote:

    > I have a web application with a page where user can go to upload data
    > files. When they click "Upload", which is an aspnet Button, I want to
    > be able to instantly hide a couple of textboxes and buttons on the
    > webpage before doing the postback. This is because if I place code to
    > do this in the server-side code block, it doesn't get executed until
    > after the upload completes - not very useful for this scenario! And so
    > I thought I would put in some client-side javascript to do the job .
    > But how do I wire up the client side function to the aspnet Button? I
    > need to be able to execute the client side javascript code block and
    > then immediately execute the server side code block afterwards. The
    > runat="server" is required for the aspnet Button, or at least that's
    > what the VS2005 compiler says. So how can I accomplish this?
    >
    >
     
    =?Utf-8?B?aGVpbg==?=, Jan 3, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nick
    Replies:
    3
    Views:
    3,201
    Eliyahu Goldin
    Dec 15, 2004
  2. Replies:
    1
    Views:
    923
    Sudsy
    Dec 8, 2004
  3. Replies:
    1
    Views:
    720
    Norman Yuan
    Mar 22, 2007
  4. goyal_85
    Replies:
    0
    Views:
    278
    goyal_85
    Jul 7, 2010
  5. matt
    Replies:
    1
    Views:
    272
    George Ogata
    Aug 6, 2004
Loading...

Share This Page