473,624 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button With No PostBack

I have an ASPX page with a bunch of System.Web.UI.W ebControls.Butt on
controls on it. By default, clicking on any of these causes a Postback. I'd
like to have it so that for a couple of these buttons, no PostBack occurs -
and rather some client-side script is executed (with no postback
subsequently occuring). I have wired up the client-side script to the
Buttons in question using Attributes.Add( blah blah blah) - now I just need
to somehow prevent the Postback from occuring. I looked to set
AutoPostBack="f alse" - but that isn't apparently an option. How can I have
Buttons that do not trigger a postback?

Thanks.
Nov 18 '05 #1
4 17091
Checkout the HTMLButton COntrol

http://samples.gotdotnet.com/quickst...bforms/ctrlref
/htmlctrl/HtmlButton/doc_button.aspx

Regards

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
Like Trevor said, use an HTML button. Inspite of the web-control-centric
view in Visual Studio.net, developers should carefully consider whether a
standard HTML control would work as well as a server control and default to
the HTML control...

But with that said, the answer to your question about the button control is
to assign a value to the CommandName property. With no CommandName value,
the button acts like a submit button. With a CommandName value, it will act
more like a standard button.

Dale

"Trevor Benedict R" <tr********@yah oo.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Checkout the HTMLButton COntrol

http://samples.gotdotnet.com/quickst...bforms/ctrlref
/htmlctrl/HtmlButton/doc_button.aspx

Regards

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3
Jeremy,

As far as I understand, your problem is that when you click on a
Button1 (which is WebControls.But ton), it calls javascript function
doSomething() and then posts the form? and you dont want it to
post the form just run javascript?

If that is the case, then here is the solution.

we know that if we do this: Button1.Attribu tes.Add("OnClic k", "return
false;")
Button1 will become non-functional, and it will not do anything when
user clicks it.

now suppose you have this javascript code in your web form:
<script language=javasc ript>
function doCalculate()
{
alert('I am called');
return false;
}
</script>

now if you do this: Button1.Attribu tes.Add("OnClic k", "return
doCalculate();" )

doCalculate will execute and return 'false'.. so your web form will not be
posted back. There maybe some cases when you want to return true
(you want to post the form after some work)

Your question is already answered tho, but there
maybe soem cases where you want to use WebControls.But ton
(to access it easily from codebehind) .but if the button have nothing
to do with server, then why not use HtmlButton control as my
fellow Trevor suggested?

--
Hope this helps,
Zeeshan Mustafa, MCSD

"Jeremy" <JA*@2.com> wrote in message
news:e1******** ******@TK2MSFTN GP12.phx.gbl...
I have an ASPX page with a bunch of System.Web.UI.W ebControls.Butt on
controls on it. By default, clicking on any of these causes a Postback. I'd like to have it so that for a couple of these buttons, no PostBack occurs - and rather some client-side script is executed (with no postback
subsequently occuring). I have wired up the client-side script to the
Buttons in question using Attributes.Add( blah blah blah) - now I just need
to somehow prevent the Postback from occuring. I looked to set
AutoPostBack="f alse" - but that isn't apparently an option. How can I have
Buttons that do not trigger a postback?

Thanks.



Nov 18 '05 #4
M,
Personally, I don't use the asp:Button. I tend to always use <input
type="button"/> and then if I need to modify it on the server, I add
runat="server". If all I need is javascript, then I don't even make it a
server control. And for submit post-back processing, I just set the
ServerClick event, and it posts back. That way I don't run into problems
with multiple buttons on my form and having a inadvertant click of the enter
button trigger a post-back.

Best regards,
Jeffrey Palermo

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zees han.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Jeremy,

As far as I understand, your problem is that when you click on a
Button1 (which is WebControls.But ton), it calls javascript function
doSomething() and then posts the form? and you dont want it to
post the form just run javascript?

If that is the case, then here is the solution.

we know that if we do this: Button1.Attribu tes.Add("OnClic k", "return
false;")
Button1 will become non-functional, and it will not do anything when
user clicks it.

now suppose you have this javascript code in your web form:
<script language=javasc ript>
function doCalculate()
{
alert('I am called');
return false;
}
</script>

now if you do this: Button1.Attribu tes.Add("OnClic k", "return
doCalculate();" )

doCalculate will execute and return 'false'.. so your web form will not be
posted back. There maybe some cases when you want to return true
(you want to post the form after some work)

Your question is already answered tho, but there
maybe soem cases where you want to use WebControls.But ton
(to access it easily from codebehind) .but if the button have nothing
to do with server, then why not use HtmlButton control as my
fellow Trevor suggested?

--
Hope this helps,
Zeeshan Mustafa, MCSD

"Jeremy" <JA*@2.com> wrote in message
news:e1******** ******@TK2MSFTN GP12.phx.gbl...
I have an ASPX page with a bunch of System.Web.UI.W ebControls.Butt on
controls on it. By default, clicking on any of these causes a Postback.

I'd
like to have it so that for a couple of these buttons, no PostBack

occurs -
and rather some client-side script is executed (with no postback
subsequently occuring). I have wired up the client-side script to the
Buttons in question using Attributes.Add( blah blah blah) - now I just need to somehow prevent the Postback from occuring. I looked to set
AutoPostBack="f alse" - but that isn't apparently an option. How can I have Buttons that do not trigger a postback?

Thanks.


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1883
by: majid | last post by:
Hi I have a webform that can show a dialog using javascript . Content of this dialog is an aspx page with a submit button .My problem is when i click the button , postback page apeares in new window while i want it apeares in the dialog?
3
9219
by: Mike Dole | last post by:
I experimented with a usercontrol (TagedTextbox), I added a tag property. The tag value however is not persisted on postback (text value's fine)? I worked around it with: Me.ViewState("tag") = txtToelichting.Tag but what's wrong with my code?
1
3545
by: Miro | last post by:
I have a webform with lots of <asp:...controls but I need couple of buttons that doesn't cause an automatic postback. I use javascript to handle these buttons. I tried two approaches with different results: <IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';" onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';" id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';" style="LEFT: 170px; WIDTH: 24px; POSITION:...
2
1426
by: MER78 | last post by:
I have two radio buttons (RB1 + RB2). The page starts with RB2 selected. Both are enabled. Action 1 - I press RB1 a postback event happens... but the event handler for RB1 (CheckedChanged) isn't called. Action 2 - I press RB2 a postback even happens... everything works good. Action 3 - I press RB1 a second time... postback event happens + the event
5
2637
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze in 1.1 since I could edit the .js file. Now in 2.0 I can no longer do this. Also, my code would have to be called after all client-side validation was done and was successful. Any ideas? TIA!
6
4435
by: Kevin Lawrence | last post by:
Hi I need to be able to prevent a Server Button from posting back when clicked, the reason for this is so I can use client-script to disable the button and then when there is a postback to save its state... Kev
2
5938
by: darrel | last post by:
I am using a javascript WYSIWYG text editor for our CMS. To grab the proper content we need to add a javacsript call to the form: Form1.Attributes.Add("onSubmit", "myOnSubmitEventHandler();") That works fine. However, we also have some dropDownLists that trigger a postback. If we change these, I still need to update the text editor, so I added attributes to them:
7
4611
by: Tim_Mac | last post by:
hi, using .net 2.0, i have a web form with lots of textboxes, drop-down-lists etc. There are lots of required field validators and regular expression validators. When i click the 'save' button, the client-side validation is executed immediately and the errors flash up on screen. However at the same time, a post-back is performed and the page is obviously un-usable while it is awaiting a response from the server. it looks very poor from...
0
1119
by: ruca | last post by:
Hi, Can anyone tell me how can I preserve the values of Attributes of a DataGrid with postback. I have a javascript function that change some attributes of some cells of a DataGrid. Then I have a button to confirm this changes. By clicking in this button postback event fires and attributes values losted. Can anyone help me and where can I get more information about this?
3
2041
by: gerry | last post by:
Sung the ASP.NET AJAX framework, and following the control creation examples from the ajax toolkit I have created a simple custom control that includes a button with a client side onClick handler. Returning false from the handler prevents postbacks in IE but in firefox the handler fires and does its thing but the postback still occurs as well. I read that changing this from an INPUT SUMIT to a BUTTON would fix this problem, however that to...
0
8231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.