asp.net crosspage postback on click doesn't run - asp.net

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.

Related

ASP.NET Textbox TextChanged and Button OnClick event interaction?

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.

ASP.NET control event handler not firing on postback?

I have a control which has an ImageButton which is tied to an OnClick event... Upon clicking this control, a postback is performed and the event handler is not called. AutoEventWireup is set to true, and I've double checked spelling etc.... We haven't touched this control in over a year and it has been working fine until a couple of weeks ago.
We have made changes to controls which load this control... so I'm wondering, what kind of changes could we have made to stop this event handler from being called? There is quite a bit of Javascript going on, so this could be the culprit too...
Edit: Some clarification... we are dynamically loading the parent control of the ImageButton in the OnLoad event of the page... if that makes sense.
AutoEventWireup is irrelevant. Is your ImageButton loaded dynamically, i.e. not written out in mark up? If it is loaded onto the page late in the Page lifecycle e.g. in PreRender then the event will not fire.
If there is a JavaScript issue your page will not even PostBack. Is that happening?
Did you give the ImageButton an ID?
I def agree with what BritishDeveloper said. I had a similar problem where I was dynamically loading controls, but I couldn't get a reference to the control using Page.FindControl("controlName") Someone pointed out that I needed to keep the page lifecycle in mind. I found out I needed to make sure to load the control in the PageInit because after doing an async postback the control was still there, but not loaded in the postback so there was no way to find it. This was all in csharp codebehind and ajax though, but I'm guessing the control isn't getting reloaded.
So, as it turns out we set the PostbackUrl property on one of our buttons in control A... this caused the event handlers for control B not to fire when a button in control B was pressed.
If you create a control dynamically. Any time you fire a postback using the new created control, you need to recreated it. Just think that your application are running at a server. How can the server hold information on controls created dynamically? Don't use Page.IsPostBack to create postback. PostbackUrl is bad solution. Workarround will be need.
I can go into a little more detail ... I just lost several hours fixing my own issue similar to the issue described here. In the course of creating some search controls, I added a pair of ImageButtons and set the PostbackUrl properties on them. A few days later while testing new code, I noticed that none of my other buttons on the webform were posting back properly. They would fire a postback, but the code-behind was behaving as if every postback was an initial page request and none of the event handlers were firing.
After several hours of troubleshooting, I came across this post. When I went back and removed the PostbackUrl from those two ImageButtons, everything went back to normal. I don't know why it was causing this issue, but the fix mentioned here worked for me. I want to add that my ImageButtons were not dynamically added ... they were in the markup and this issue still cropped up. Search your markup for any controls with PostbackUrl set ... remove that (program around it if needed) ... see if your event handlers will fire properly.

How do I force a full postback from codebehind?

I'd like to programmatically force a full page postback to occur after an event is fired by one of the child controls. I can't add any triggers to make this work so it will have to be done via code. Thanks.
Sorry, don't understand. By the time an event in codebehind is running, a postback has already happened.
If you mean a client side event then setup OnClientClick to call what is returned by the following after your other client side functionality:
Page.ClientScript.GetPostBackEventReference(control, "")
(It will be something like __dopostback)

How can I trigger a server-side event from a client-side event?

Short version
All I need is that, in a ModalPopUp, when the DoubleClick event of a ListItem fires, the click event of my OK button should be executed.
Detail
I have a ModalPopUpExtender, which hosts a user control. The user control has an OK and a Cancel button. Along with that, it has a dynamic ListBox added to it. So far, I've considered the following possible solutions:
Use Ajax.Net. But, I cannot afford to have a WebMethod.
Use a ClientScriptCallBack. This will need a lot of JavaScript, since I have made almost every control dynamic.
Is there any other way apart from using an UpdatePanel?
Have a look at this way using __doPostback
calling a VB.net function from javascript

ASP.NET - AJAX - Partial followed by full postback problem

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

Resources