Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-19
7
Medium Priority
?
234 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 500 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

876 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