Solved

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

Posted on 2004-08-19
7
228 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Anyway to make "All" the default in the dropdown? 6 36
ASP.NET 5 Templates 2 78
Ajax Panel Not Updating When Triggered By Timer 4 72
jquery progress bar 3 41
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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