Solved

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

Posted on 2004-08-19
7
226 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

15 Experts available now in Live!

Get 1:1 Help Now