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

J

Joey

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?
 
G

Guest

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top