Link to home
Start Free TrialLog in
Avatar of RichardFox
RichardFox

asked on

Button that doesn't post back, but has onchange javascript function

I want to have a button that looks like a button, but doesn't post back to the server... so I guess I couldn't really call it a button. I have a button control with

      addTransBTN.Attributes.Add("onclick","openNewWin();");

but it still posts back to the server when clicked, causing my page to reload. Do I use a different control, or how does one normally work around this?
SOLUTION
Avatar of gspronych
gspronych

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RichardFox
RichardFox

ASKER

ok, but how do I work with this in a codebehind file?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want it to run codebehind richardfox it needs to be a server control as Baan said.
BUT a server control will cause a postback.

If the name of the control is Button1, put this code in your page_load
        Button1.AutoPostBack = False


No.. gspronych  , if it is an HTML control.. it won't.
I need to create these controls dynamically. I understand the suggestion, but I need to add the HTML button when I create the rest of my controls, so I can't drag it from the toolbox and right click it and specify "Run at server". How can I do this from code?
I created a dynamic control

HtmlControls mybutton;

and set the onclick function, works great, thanks!