473,396 Members | 2,037 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,396 software developers and data experts.

btnSubmit.click not firing when another control does postback

greetings -

I have a btnSubmit button with a Handles btnSubmit.click which works great
if all the user does is click that button.

But, if the user ALSO changes a text box on the page (which has it's own
event and autopostback=true) before clicking submit then it fires the text
box event but never fires the btnSubmit event. (I follow it in the trace).

Surely both event handlers should be fired? Any hints on identifying what I
have done wrong in the code?

--
ttfn (ta ta for now)
Nov 19 '05 #1
8 11128
When you specify AutoPostBack=true, you're asking a postback to happen as
soon as the item has changed. So when the user tabs off of the TextBox then
it fires the client-side onchange event which triggers a postback -- this
happens *before* the user has had a chance to click the button, so thats
why the button's click doesn't fire.

Disable AutoPostBack on the textbox and when they click the button you'll
get both events in one postback to the server.

-Brock
DevelopMentor
http://staff.develop.com/ballen
greetings -

I have a btnSubmit button with a Handles btnSubmit.click which works
great if all the user does is click that button.

But, if the user ALSO changes a text box on the page (which has it's
own event and autopostback=true) before clicking submit then it fires
the text box event but never fires the btnSubmit event. (I follow it
in the trace).

Surely both event handlers should be fired? Any hints on identifying
what I have done wrong in the code?


Nov 19 '05 #2
Thanks for Brock's inputs.

Hi Walesboy,

In addition to what Brock has mentioned, I think you can also have a look
at the different events in asp.net's webform control model:

#Processing Postback Data
http://msdn.microsoft.com/library/en...ivingpostbackd
atachangednotifications.asp?frame=true

#Capturing Postback Events
http://msdn.microsoft.com/library/en...ivingpostbacke
ventnotifications.asp?frame=true

What makes the page be submited to serverside is the "PostBack" and
eachtime , there is only one postback event( of a certain postbackable
control) can be fired. Those submit buttons or ImageButtons by default
will cause postback. However, TextBox by default won't cause the page
postback (but it's TextChange event still have effect if the page is
submited by other postback event as long as the its Text is changed).
When TextBox enable AutoPostBack, any textchange at clientside will cause
the page be posted back, but since it is TextBox that cause the postback,
Button's postback event won't be fired.

#Note: TextBox's Change event is not a postback event, it is a data changed
event which are different from each other. You can refer to the above MSDN
reference.

If there is anything unclear, please feel free to post here. Thanks,
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3
Steven / Brock, thanks for your responses, but I'm not convinced that a
fundamental limitation of asp.net is that only one event will be fired. I
have an earlier version of this same app (actually a different project, but
same business solution) running on the production server which DOES work as I
would hope.

When the user changes the quantity text box, and then presses submit, it
BOTH accepts the change to the text box AND carries out the submit (which
updates the database). The text box has AutoPostBack=true.

So I tried promoting my test code to a place on the production server, and
now it ALSO works as I would hope.

So there would seem to be a difference between my local .net/iis version and
the production server such that multiple events ARE fired when the user
initiates them on a page.

Any ideas what versioning to check for this 'fix' to my local?
Nov 19 '05 #4
Hi Walesboy,

Thanks for your response. AS you said that there was a former page in which
you also have a TExtBox (AutoPostBack= true) and a submit button. However,
that page can let us change the Textbox's text and post back the page (with
both TextChanged, Button_Click event be fired) ,yes? I'm a bit surprised
on this since the shouldn't be the expected behavior of the ASP.NET's
webform postback model.

Would you send me a simple repro page? In addition, if you do want to let
the page's button_click also fired when we change a TextBox's text, we can
use the html <input type="text" > element and add some "onchange"
clientside script which will invoke the button's click event at clientside
so as to post back the page. I think this is a normal approach.

Please feel free to let me know if there is anything else you found or
need assistance. Thanks,
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #5
Hi Steven -

well finally got time to create a little test sample, and (of course) it
doesn't reproduce the symptom. I can still consistently get it to do BOTH
the txt autopostback and the btnclick at the same post in my full example, so
not sure what is different.

my txt autopostback event is:
Private Sub txtUnitCost_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtUnitCost.TextChanged
If Not (IsNumeric(Me.txtQty.Text) And
IsNumeric(Me.txtUnitCost.Text)) Then
OutputNote("Unit Cost must be numeric")
Else
Me.lblTotalCost.Text = FormatCurrency(Me.txtQty.Text *
Me.txtUnitCost.Text, 0, , , )
End If
End Sub

my btn event is:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
If ValidatePage() = True Then
'' save the exp
myExp.SaveExp()
If Me.chkStay.Checked = False Then
Response.Redirect("CAPEX4a.aspx")
Else
OutputNote(myExp.ExpDesc + " was successfully added")
End If
End If
End Sub

note that if I change the unit cost, and THEN click the submit button
WITHOUT tabbing out of the txtUnitCost object, it will save the correctly
modified quantity to the database. On my own localhost, however, it will
just sit there and do nothing until I click the btnSubmit a second time.

Nov 19 '05 #6
Hi Walesboy,

Thanks for your followup.
If the thing is just as you mentioned, I think your localhost page's
behavior is the resonable one:
====================
On my own localhost, however, it will
just sit there and do nothing until I click the btnSubmit a second time.
===================

Based on my local test, when there is an AutoPostBack TExtBox and submit
button, when I change the textbox and click the submit button without tab
out the textbox, only the TextChange event will fire(button_click won't
take place). Have you tried testing on some other boxes or create a new
project ?

In addition, what's your production server's asp.net/.net runtime version?
Is it updated to t he latest version with all the .net framework service
pack? I think you can also try using the aspnet_regiis -c command to
reregister the ASP.NET global script files on that server to see whether
this help.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #7
Thanks Steve - I guess the irony here is that the unexplained action of
firing both events on the server is actually what I want (I believe it's a
more intuitive interface for the user, who doesn't have to sit there
wondering why nothing happened when they clicked submit), so I'm tempted to
let sleeping dogs lie.
Nov 19 '05 #8
Hi walesboy,

Thanks for your reply.
If you do feel that both events fire is the one you like, it's ok you let
that server going though it really make me feel a bit upset. Anyway, if you
meet any further problem or if you decide to modify your page code so as to
avoid that behavior , please feel free to post here. I'll be glad to assist
you :--)

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 19 '05 #9

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

Similar topics

1
by: w | last post by:
Hi everyone, Just wondering if any one knows whether an event fires when focus switches onto a control. I need to perform some actions when some one clicks on and off a grid... is there...
7
by: moondaddy | last post by:
I'm building a page in vb.net with several user controls on it. I'm using user controls instead of a frames page since I've seen this recommended many times in this user group. I want just one of...
2
by: Devin Fensterheim | last post by:
Does anyone know of an issue with a control's viewstate not persisting when dynamically adding custom controls to a web form using AddAt? If a control is added to an HTML form directly using the...
7
by: Michael Groeger | last post by:
Hi all, I have designed user controls. One search control where I can search for items in the database and show them in a grid. This control also has a button which simply exposes it's click...
2
by: Nemo | last post by:
Hi, I have i fishy problem when I have e Repeater with user controls. page_load { if (!isPostBack) { repeater.databind(); }
3
by: John Smith | last post by:
How can I find out which control performed PostBack?
1
by: DCC700 | last post by:
After upgrading a web application from VS 2003 to 2005 there is a page where any control event that should cause a postback instead generates an Invalid character error on the page. For example a...
2
by: Sunny | last post by:
Hi, I have an application using IE6 before and now we have upgraded to IE7. After upgrading, I have been having issues with button click event when embedded JavaScript file into the page....
10
by: John Kotuby | last post by:
Hello all... I am working on an ASP.NET 2.0 application with VS2005 and VB. I have chosen to use popup windows in some cases because it makes the user experience better (according to all the users...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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,...
0
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...

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.