Solved

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

Posted on 2004-08-19
7
225 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:RichardFox
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Assisted Solution

by:gspronych
gspronych earned 125 total points
ID: 11846795
If you want a button that doesn't do a server postback, you want a input box.
<INPUT type="button" value="Button">

Or click the toolbox, select HTML, and drag the button on the form.

The HTML button does not perform a server side postback
0
 

Author Comment

by:RichardFox
ID: 11847014
ok, but how do I work with this in a codebehind file?
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 125 total points
ID: 11847015
Hi there ..
get an HTML button as gspronych said. Right click on it. Make it "Run at server". Assign a name to it using Property box. Say "Button1". In the page load add the attribute...

        Button1.Attributes.Add("OnClick", "javascript:openNewWin();")

-Baan
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:gspronych
ID: 11852853
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


0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11853503
No.. gspronych  , if it is an HTML control.. it won't.
0
 

Author Comment

by:RichardFox
ID: 11870451
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?
0
 

Author Comment

by:RichardFox
ID: 11872583
I created a dynamic control

HtmlControls mybutton;

and set the onclick function, works great, thanks!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now