473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Button With No PostBack

I have an ASPX page with a bunch of System.Web.UI.WebControls.Button
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="false" - but that isn't apparently an option. How can I have
Buttons that do not trigger a postback?

Thanks.
Nov 18 '05 #1
4 17072
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********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.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.Button), 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.Attributes.Add("OnClick", "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=javascript>
function doCalculate()
{
alert('I am called');
return false;
}
</script>

now if you do this: Button1.Attributes.Add("OnClick", "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.Button
(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**************@TK2MSFTNGP12.phx.gbl...
I have an ASPX page with a bunch of System.Web.UI.WebControls.Button
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="false" - 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.zeeshan.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Jeremy,

As far as I understand, your problem is that when you click on a
Button1 (which is WebControls.Button), 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.Attributes.Add("OnClick", "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=javascript>
function doCalculate()
{
alert('I am called');
return false;
}
</script>

now if you do this: Button1.Attributes.Add("OnClick", "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.Button
(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**************@TK2MSFTNGP12.phx.gbl...
I have an ASPX page with a bunch of System.Web.UI.WebControls.Button
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="false" - 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
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...
3
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")...
1
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...
2
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)...
5
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...
6
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...
2
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();") ...
7
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,...
0
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...
3
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.