By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

can i prevent a button from posting back when clicked?

P: n/a
I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks
Jul 18 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
why would you want to do that?

bill wrote:
I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks
Jul 18 '06 #2

P: n/a
If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common event
handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input which
consists of a table with 100 cells, each containing a button corresponding
to a value between 1 and 100. The value is the command argument of the
button. When one of the buttons is clicked it fires an event, and the
selected value is saved. This event should be the common event handler used
by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
why would you want to do that?

bill wrote:
>I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks

Jul 18 '06 #3

P: n/a
Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some other
controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't clicked
anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a dropdown.

You can stop buttons from posting back. However, when the page does finally
post back to the server, nothing will happen. You would have to manually in
javascript keep track of which buttons were clicked, send that up to the
server on the next postback, and process this manually. You can do this,
but from what you described it sounds like having buttons for data entry is
not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input which
consists of a table with 100 cells, each containing a button corresponding
to a value between 1 and 100. The value is the command argument of the
button. When one of the buttons is clicked it fires an event, and the
selected value is saved. This event should be the common event handler
used by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
>why would you want to do that?

bill wrote:
>>I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks


Jul 18 '06 #4

P: n/a
I would much prefer to create this interface the way I think it should look,
and work the way Marina Levit thinks it should work.

However, the client does not want a row of radio buttons or checkboxes or a
dropdown - they want a solid bar marked by 100 dots, each corresponding to a
value which will be saved accordingly.

I'm interested in what model you would recommend to achieve this.

Buttons work fine, except that they will post back. If I could just set
AutoPostBack to false for the button, wire up an event handler, and treat
the button click just like a dynamically created RadioButtonList
SelectedIndexChanged event when the page does post back (when a 'Save'
button is clicked) it would work exactly as the client wants.

Thanks!

Bill

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some
other controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't
clicked anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a dropdown.

You can stop buttons from posting back. However, when the page does
finally post back to the server, nothing will happen. You would have to
manually in javascript keep track of which buttons were clicked, send that
up to the server on the next postback, and process this manually. You can
do this, but from what you described it sounds like having buttons for
data entry is not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input which
consists of a table with 100 cells, each containing a button
corresponding to a value between 1 and 100. The value is the command
argument of the button. When one of the buttons is clicked it fires an
event, and the selected value is saved. This event should be the common
event handler used by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegr oups.com...
>>why would you want to do that?

bill wrote:
I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks



Jul 18 '06 #5

P: n/a
sam
I'd just create a custom control for that row of dots. You can render
it however you want it with a strictly client side onclick for every
dot where you just set an attached hidden field to the number you pass
in on the onlick (from 1-100 depending on the dot clicked). Then just
do a page.request.form("hidden_field_id") to get that value on the
sever side. Or something more clever if you want.

I'm not sure exactly what you are doing but you should just make
everything client side. Dont add all those clunky server postback
buttons to make up the row of dots.

-Sam

bill wrote:
I would much prefer to create this interface the way I think it should look,
and work the way Marina Levit thinks it should work.

However, the client does not want a row of radio buttons or checkboxes or a
dropdown - they want a solid bar marked by 100 dots, each corresponding to a
value which will be saved accordingly.

I'm interested in what model you would recommend to achieve this.

Buttons work fine, except that they will post back. If I could just set
AutoPostBack to false for the button, wire up an event handler, and treat
the button click just like a dynamically created RadioButtonList
SelectedIndexChanged event when the page does post back (when a 'Save'
button is clicked) it would work exactly as the client wants.

Thanks!

Bill

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some
other controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't
clicked anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a dropdown.

You can stop buttons from posting back. However, when the page does
finally post back to the server, nothing will happen. You would have to
manually in javascript keep track of which buttons were clicked, send that
up to the server on the next postback, and process this manually. You can
do this, but from what you described it sounds like having buttons for
data entry is not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input which
consists of a table with 100 cells, each containing a button
corresponding to a value between 1 and 100. The value is the command
argument of the button. When one of the buttons is clicked it fires an
event, and the selected value is saved. This event should be the common
event handler used by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
why would you want to do that?

bill wrote:
I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks
Jul 18 '06 #6

P: n/a
You could probably tie the onclick client side event to a javascript method
that cancels the postback for each button while updating a hidden client
side string array field with each button that had been pressed, leaving a
submit button to effect the postback. Marina is right though, buttons are
not the best approach for this - its fiddly and over complicated for what
you describe.

Does your client have no comprehension of good user centric design, and no
understanding of what specific elements of HTML should be used for? Go with
radio groups or checkboxes - it just makes sense.

Regards

John Timney (MVP)
"bill" <be****@datamti.comwrote in message
news:e4**************@TK2MSFTNGP05.phx.gbl...
>I would much prefer to create this interface the way I think it should
look, and work the way Marina Levit thinks it should work.

However, the client does not want a row of radio buttons or checkboxes or
a dropdown - they want a solid bar marked by 100 dots, each corresponding
to a value which will be saved accordingly.

I'm interested in what model you would recommend to achieve this.

Buttons work fine, except that they will post back. If I could just set
AutoPostBack to false for the button, wire up an event handler, and treat
the button click just like a dynamically created RadioButtonList
SelectedIndexChanged event when the page does post back (when a 'Save'
button is clicked) it would work exactly as the client wants.

Thanks!

Bill

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some
other controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't
clicked anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a dropdown.

You can stop buttons from posting back. However, when the page does
finally post back to the server, nothing will happen. You would have to
manually in javascript keep track of which buttons were clicked, send
that up to the server on the next postback, and process this manually.
You can do this, but from what you described it sounds like having
buttons for data entry is not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl. ..
>>If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input
which consists of a table with 100 cells, each containing a button
corresponding to a value between 1 and 100. The value is the command
argument of the button. When one of the buttons is clicked it fires an
event, and the selected value is saved. This event should be the common
event handler used by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googleg roups.com...
why would you want to do that?

bill wrote:
I dynamically create buttons and associate them with an event using
AddHandler.
>
I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.
>
How I stop the buttons from posting back when they are clicked?
>
Thanks



Jul 18 '06 #7

P: n/a

Can you point me to a helpful resource for building a custom control which
would raise a server side event?

"sam" <sa*************@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
I'd just create a custom control for that row of dots. You can render
it however you want it with a strictly client side onclick for every
dot where you just set an attached hidden field to the number you pass
in on the onlick (from 1-100 depending on the dot clicked). Then just
do a page.request.form("hidden_field_id") to get that value on the
sever side. Or something more clever if you want.

I'm not sure exactly what you are doing but you should just make
everything client side. Dont add all those clunky server postback
buttons to make up the row of dots.

-Sam

bill wrote:
>I would much prefer to create this interface the way I think it should
look,
and work the way Marina Levit thinks it should work.

However, the client does not want a row of radio buttons or checkboxes or
a
dropdown - they want a solid bar marked by 100 dots, each corresponding
to a
value which will be saved accordingly.

I'm interested in what model you would recommend to achieve this.

Buttons work fine, except that they will post back. If I could just set
AutoPostBack to false for the button, wire up an event handler, and treat
the button click just like a dynamically created RadioButtonList
SelectedIndexChanged event when the page does post back (when a 'Save'
button is clicked) it would work exactly as the client wants.

Thanks!

Bill

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some
other controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't
clicked anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do
not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a
dropdown.

You can stop buttons from posting back. However, when the page does
finally post back to the server, nothing will happen. You would have
to
manually in javascript keep track of which buttons were clicked, send
that
up to the server on the next postback, and process this manually. You
can
do this, but from what you described it sounds like having buttons for
data entry is not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists,
dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input
which
consists of a table with 100 cells, each containing a button
corresponding to a value between 1 and 100. The value is the command
argument of the button. When one of the buttons is clicked it fires
an
event, and the selected value is saved. This event should be the
common
event handler used by the other controls on the page.

I want all the control events to be processed one time when the page
is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googlegr oups.com...
why would you want to do that?

bill wrote:
I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks



Jul 19 '06 #8

P: n/a
Bottom line: No.

"bill" <be****@datamti.comwrote in message
news:uy**************@TK2MSFTNGP03.phx.gbl...
>I dynamically create buttons and associate them with an event using
AddHandler.

I want all the button events to fire at one time, when the page is posted,
instead of when each button is clicked.

How I stop the buttons from posting back when they are clicked?

Thanks


Jul 19 '06 #9

P: n/a
Radio buttons or checkboxes don't particularly make sense if the client
requires a granularity in value from 1 to 100.

I agree with the problems with buttons, since I can't prevent autopostback
and wire up a deferred event.

I guess I'll have to use a client side javascript solution, although I
prefer to keep my logic on the server.

"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:kZ********************@eclipse.net.uk...
You could probably tie the onclick client side event to a javascript
method that cancels the postback for each button while updating a hidden
client side string array field with each button that had been pressed,
leaving a submit button to effect the postback. Marina is right though,
buttons are not the best approach for this - its fiddly and over
complicated for what you describe.

Does your client have no comprehension of good user centric design, and no
understanding of what specific elements of HTML should be used for? Go
with radio groups or checkboxes - it just makes sense.

Regards

John Timney (MVP)
"bill" <be****@datamti.comwrote in message
news:e4**************@TK2MSFTNGP05.phx.gbl...
>>I would much prefer to create this interface the way I think it should
look, and work the way Marina Levit thinks it should work.

However, the client does not want a row of radio buttons or checkboxes or
a dropdown - they want a solid bar marked by 100 dots, each corresponding
to a value which will be saved accordingly.

I'm interested in what model you would recommend to achieve this.

Buttons work fine, except that they will post back. If I could just set
AutoPostBack to false for the button, wire up an event handler, and treat
the button click just like a dynamically created RadioButtonList
SelectedIndexChanged event when the page does post back (when a 'Save'
button is clicked) it would work exactly as the client wants.

Thanks!

Bill

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some
other controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't
clicked anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a dropdown.

You can stop buttons from posting back. However, when the page does
finally post back to the server, nothing will happen. You would have to
manually in javascript keep track of which buttons were clicked, send
that up to the server on the next postback, and process this manually.
You can do this, but from what you described it sounds like having
buttons for data entry is not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl.. .
If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input
which consists of a table with 100 cells, each containing a button
corresponding to a value between 1 and 100. The value is the command
argument of the button. When one of the buttons is clicked it fires an
event, and the selected value is saved. This event should be the
common event handler used by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.google groups.com...
why would you want to do that?
>
bill wrote:
>I dynamically create buttons and associate them with an event using
>AddHandler.
>>
>I want all the button events to fire at one time, when the page is
>posted,
>instead of when each button is clicked.
>>
>How I stop the buttons from posting back when they are clicked?
>>
>Thanks
>




Jul 20 '06 #10

P: n/a
sam
Hey uhh sorry I'm kindof time pressed right now and my laptop is out
for repair.

Just implement IPostBackEventHandler in your composite control class
and call Page.RegisterRequiresPostbackEvent(this) and then you will
always get that clickback in the method of that interface (I can't
remember exactly the name now). Override the Render() method and
output whatever html you want to its completely up to you (although if
you inhereit from CompositeControl it will put a span tag around
everything).

I can help you more if you need it. Right now I'm supposed to be
working :).

-Sam

Jul 20 '06 #11

P: n/a

BillE wrote:
Radio buttons or checkboxes don't particularly make sense if the client
requires a granularity in value from 1 to 100.

I agree with the problems with buttons, since I can't prevent autopostback
and wire up a deferred event.

I guess I'll have to use a client side javascript solution, although I
prefer to keep my logic on the server.

"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:kZ********************@eclipse.net.uk...
You could probably tie the onclick client side event to a javascript
method that cancels the postback for each button while updating a hidden
client side string array field with each button that had been pressed,
leaving a submit button to effect the postback. Marina is right though,
buttons are not the best approach for this - its fiddly and over
complicated for what you describe.

Does your client have no comprehension of good user centric design, and no
understanding of what specific elements of HTML should be used for? Go
with radio groups or checkboxes - it just makes sense.

Regards

John Timney (MVP)
"bill" <be****@datamti.comwrote in message
news:e4**************@TK2MSFTNGP05.phx.gbl...
>I would much prefer to create this interface the way I think it should
look, and work the way Marina Levit thinks it should work.

However, the client does not want a row of radio buttons or checkboxes or
a dropdown - they want a solid bar marked by 100 dots, each corresponding
to a value which will be saved accordingly.

I'm interested in what model you would recommend to achieve this.

Buttons work fine, except that they will post back. If I could just set
AutoPostBack to false for the button, wire up an event handler, and treat
the button click just like a dynamically created RadioButtonList
SelectedIndexChanged event when the page does post back (when a 'Save'
button is clicked) it would work exactly as the client wants.

Thanks!

Bill

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Shouldn't you use radio buttons, or checkboxes, or dropdowns, or some
other controls to let your users answer the questionaire?

A button indicates "do something now".

After the user clicks a button to select an answer, the button isn't
clicked anymore - the user couldn't see what they selected anyway.

Buttons are not meant to have values in terms of data entry. You do not
enter data by clicking buttons.

You enter data by selecting the appropriate radio button, or typing
something into an input control, or selecting something from a dropdown.

You can stop buttons from posting back. However, when the page does
finally post back to the server, nothing will happen. You would have to
manually in javascript keep track of which buttons were clicked, send
that up to the server on the next postback, and process this manually.
You can do this, but from what you described it sounds like having
buttons for data entry is not the right model to begin with.

"bill" <be****@datamti.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl. ..
If I tell you why, will you tell me how?

My page is built dynamically with a number of controls for data entry
purposes (like a questionnaire), including radio button lists, dropdown
lists, checkbox lists, textboxes... Each control is wired to a common
event handler which processes the input when the page is posted.

In addition, I have constructed a scale or slider control for input
which consists of a table with 100 cells, each containing a button
corresponding to a value between 1 and 100. The value is the command
argument of the button. When one of the buttons is clicked it fires an
event, and the selected value is saved. This event should be the
common event handler used by the other controls on the page.

I want all the control events to be processed one time when the page is
posted.

Thanks
Bill
<ne**********@gmail.comwrote in message
news:11*********************@p79g2000cwp.googleg roups.com...
why would you want to do that?

bill wrote:
I dynamically create buttons and associate them with an event using
AddHandler.
>
I want all the button events to fire at one time, when the page is
posted,
instead of when each button is clicked.
>
How I stop the buttons from posting back when they are clicked?
>
Thanks


*sigh* since you insist on doing it the "fiddly way"
There are plenty of references out there, for building custom controls.

here's a quick 'n dirty ScaleControl.vb

Imports System.ComponentModel
Imports System.Web.UI

<DefaultProperty("Value"), ToolboxData("<{0}:ScaleControl
runat=server></{0}:ScaleControl>")Public Class ScaleControl
Inherits System.Web.UI.HtmlControls.HtmlInputHidden

<Bindable(True), Category("Appearance"), DefaultValue("0")Shadows
Property Value() As Integer
Get
Return CInt(MyBase.Value)
End Get
Set(ByVal Value As Integer)
MyBase.Value = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
Dim i As Integer

MyBase.Render(output)
For i = 0 To 99
output.Write(String.Format("<INPUT type=""Button""
value=""{1}"" onclick=""javascript:if(document.getElementById('{ 0}')){{
document.getElementById('{0}').value = {1} }}; return false;"" />",
Me.ClientID, i))
Next
End Sub
End Class

not pretty, but it'll give you a place to start.

To use, just drop it on a page, like any other control

Hope this helps
-- a --

Jul 20 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.