I've got an ASP.NET application that I'm accessing through Google Chrome. On a particular page I've got an asp:TextBox with a OnTextChanged event that recalculates a few other fields on the page. I've also got an asp:LinkButton with an OnClick event that saves the changes to the database.
I was facing a problem where the user left the TextBox by clicking on the save button. The button was firing before the TextChanged event so the changes were not being captured in the save. I fixed this by duplicating the TextChanged logic at the beginning of the save method. Did some testing before I committed these changes and everything was working fine.
But now my tester is facing a different problem. When he changes the text field and clicks the save button, the OnTextChanged event is firing to update the other values on the page but the OnClick event for the save button is not firing at all. He has to click the save button a second time to get the OnClick event to fire. I tested the same functionality on my machine and it's still working fine for me. He and I are looking at exactly the same page in the same environment with the same database. I had my tester clear his cache etc. The only difference I can find is that my Chrome version is "14.0.835.202 m" while his is simply "14.0.835.202".
Are there any known issues with Chrome and ASP.NET where event firing can be non-deterministic or something? Anyone have any other idea why this might be happening? Thanks for your time!
I believe this is a known issue.
One option is to disable the button (client-side) when the user is typing in the TextBox, and enable it after the TextChanged event completes.
Another option is to remove AutoPostBack="true" and use AJAX instead.
Related
I have the following scenario:
UserControlA contains a <asp:Button id="bSomeid" onClick="AddItem" /> with some code to an item to a shopping basket in AddItem.
UserControlB contains some LinkButton's that dynamically add a selection of UserControlA to the page in the OnClick event.
This is all done in an UpdatePanel. It is a little more complicated but I have pruned the information to what I believe is causing the problem, I will add more information if necessary.
The problem I have is that it takes 2 clicks for the AddItem event to trigger after I have added the items to the page after clicking the LinkButton.
I understand why this is happening - it is to late in the page cycle to register events for the next post back in the onclick - but can anyone think of a way around this? Can I force an event to be triggered on the next postback? I have tried to think of a way to run my code in page_load but I requuire access to the sender in the onClick.
Using .NET 4.0.
EDIT
I managed to find a way to get the link button sending the request in the Page_Load (using Request.Form["__EVENTTARGET"];) so I moved my code to the Page_load event. It still requires 2 clicks so I am assuming it isn't something to do with the onClick being registered to late.
Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?
If your suspicion about being late in page life cycle is true then you can try using ScriptManager.RegisterAsyncPostBackControl method to register dynamically added controls in the link button click - considering that your button is within user control, you need to add public method into UserControlA that would actually register the button bSomeid1 and link button click from UserControlB would actually call the A control's method.
EDIT :
Another cause for button click not happening can be that button being dynamic control is not added in the page hierarchy when post-back happens (or it gets added very late in the page life cycle when the post back data is already processed). A really full-proof solution should add dynamic controls back to the page hierarchy in page_load it-self (and strictly maintaining same controls ids within hierarchy). If that's not possible then you can sniff the request (Request.Form) to detect the post-back.
In your case, you should ascertain if the button is indeed causing the post-back on each click. If yes, what is the POST data (Request.Form) for the first request - what is the __EVENTTARGET value on the first click (and post-back)? That should start your trouble-shooting.
On the other hand, a simple work-around could be to use html anchor element (you can still use link button) and have a javascript handler in the click event that would set some hidden variable and then submit the form (you can simulate the click on hidden button to trigger ASP.NET client side submit pipeline) . Now the hidden variable value can be used on the post-back to determine which link button has been clicked.
"Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?"
Does it require two clicks on the control, or does it take accept a single click elsewhere on the screen, and then fire first time with a single click on the control?
I have my own (similar) issue with the Updatepanel where the first (expected) trigger does not fire and it seems that a single click elsewhere, and then the subsequent triggers fires first time (which totals 2 clicks)
[edit] Since you are working on this ATM, it may help me as well. Do you have a textbox with a trigger event on it? I do, and if I leave this blank (so that it does not fire) then there is no need for a second click.
I'm a rookie in .net. I'm using an AjaxToolKit Accordion Control and when I put a button in, the "onclick" event is not raising. When I use a dropDownList, if I select "autoPostBack", the event raises normaly (instead, nothing occours). But with buttons I cannot define the "autoPostBack" (its implicit?). It's bringing me several troubles.
Thank you if you can help.
I've discovered the problem (moreover two problems): I'm using AjaxControlToolKit MaskEditExtenders and MaskEditValidators, and a PopUpControlExtender. When the form isn't fulfilled correctly, the MaskEditExtenders/Validators somehow disables form submiting. Also, TargetControlID property of popupControlExtender was set to the button in question. In this case, the event isn't raised.
I am trying to get a crosspage postback to work in asp.net 2.0 the issue I seem to be having is the button that I press is meant to use it's on click event to store some session variables based on the values of other controls. This button has crosspage postback property to the relevant page.
The on click event seems to not run at all, it just seems to perform the postback to the other page straight away.
Is this standard behavior? Any work around?
I think I have found my answer
http://community.sgdotnet.org/blogs/chuawenching/archive/2007/03/08/ASP.NET-2.0-DataGrid_2F00_GridView-CrossPage-PostBack-.aspx
Seems like the transfer will be instant, no onClick event will run. The alternative is to use Server.Transfer in the onClick event.
Any other comments appreciated.
I've a page that has a series of web controls. One of these is a textbox with AutoPostBack turned off.
The way the page operates is that a button is clicked to save the form data. This button sits outside of the updatepanel.
So when I hit the save button the partial postback happens for the dropdownlist and after this postback has completed a full postback fires for the save button. However when the full postback fires the form data is returned to the state before the save button was clicked - i.e. my changes are removed.
I believe this could be to do with the viewstate being returned from the partial update and that viewstate not updating in the page before the full postback fires - or it getting corrupted.
Does anyone have any ideas?
Thanks.
Don't mean to sound negative but these scenarios are what made me give up "by the book" ASP.net AJAX. Learning jQuery /w simplistic ASP.net forms /w NO postbacks has lead me to build more useful and cooler UI experiences than what I had to battle to get working with update panels etc.
If you set UpdateMode="Conditional" and ChildrenAsTriggers="true" on your UpdatePanel, that will ensure the partial postback only executes when the DropDownList's postback event fires, not when the Button is clicked.
Thanks for the quick response! However I need the save buttons click event to fire too. The order in which the events fire is perfect:
dropdownlist changed event (partial)
save button click event (full)
The problem is the loss of form data after the partial postback.
Many thanks.
I've already posted a solution to this on another post. This simple code will ensure that your viewstate works with both the postback and partial postback.
Ideas for how to deal with viewstate when using ASP.NET AJAX and update panels
I have an gridview that I am adding onclick events to a checkbox column via:
cb.InputAttributes.Add("onclick", "checkClick()");
everything works fine, but when the user clicks the save button on the form, (which is within the updatepanel), suddenly the onclick event of the checkboxes stops firing!
Is this a problem with the ASP.NET AJAX?
The weird thing is that I am seeing the onclick event on the source, it just doesn't fire.
Help!
The source will show you the state of the document when first received from the server, not the current state of the DOM. What is likely happening is the update panel content is being replaced by new HTML content. The elements to which the original click events were bound are no longer in the dom.
The onclick events will need to re-bound to wire-up to the new elements that have arrived.