UpdatePanel does full postback first time - c#

I have a custom control that has an update panel in it. Within the update panel, there are no custom controls, but there are custom controls outside the update panel. All controls have an ID set as do the parents of the controls. Inside the update panel is a repeater that has controls that should trigger an async postback. The update panel has an update mode of conditional and children as triggers is off. The update panel renders standalone divs, not table cells. EnablePartialRendering is on on the script manager.
Each repeater item has numerous textboxes, but two of them have autopostback turned on. Inside the repeater ItemDataBound event, I register the control with the script manager's RegisterAsyncPostBackControl.
If I edit either textbox, it does a callback correctly. But after the first one is edited, if you edit the other one, it does a full postback. It doesn't matter which one is done first. But after it's done its postback, if you edit either of the textboxes, it does callbacks correctly.
I've tried several things like changing the UpdateMode and ChildrenAsTriggers properties to various combinations. Nothing seems to work.
Any suggestions?

A lot of things can cause this, compare UpdatePanel causes full page postback with LinkButton in ListView in UpdatePanel causes full postback.
You'll need to provide more information, e.g. .NET Framework version, IIS version etc. exact ASP.NET markup etc
But since you asked for "Any suggestions?" try looking through these questions

Related

RequiredFieldValidators stop working after UdpatePanel postback inside UserControl

I have a webforms page with 2 UpdatePanels: udpGrid for a gridview and udpFormViews with a ajaxToolkit:TabContainer surrounding 3 tabs for Insert and Editing records from the grid, and a repeater with it's own item template for editing related data to the main record. The edit tab is invisible on Page_Load. Inside the insert and edit tab resides the same Usercontrol which contains a Formview. the formview is set to insert mode by default but has an insert and edit item template with a footer template for save/update/cancel buttons, and when editing The second instance of the usercontrol gets set to edit mode and loaded and shown. It also contains a footer template containing the insert udpate and cancel commandbuttons to trigger the FormView's native inserting/updating/cancel events. RequiredField valdators on the insert FormView UserControl works fine from start and after inserting, but as soon as i do a postback to show the edit FormView usercontrol or the Repeater on hte 3rd tab (which has no relation to the Usercontrol containing the UserControl) the RequiredFieldValidators on the insert formview stop working at all, and even in code validating it's insert-validationgroup returns valid while the requiredField shows empty text in code.
For some reason the insert FormView UserControl loses it's validation logic completely after any postback but it's own Insert, with or without the second instance of the UserControl present. I don't load or change anything to the insert Formview UserControl and i can keep inserting without breaking the Validation but whenever a postback occurs outside of it it breaks. Even updates on the other UpdatePanel (udpGrid) break it and i have no way to test validation on the insert UserControl clientside or serverside using the RequiredFieldValidators. The Edit UserControl does still fire its validators but besides showing the error text on screen it ignores it and still updates the record, also ignoring server side the edit-validationgroup validation.
Does anyone know what is happening? it seems putting these Formvies in UserControls kind of breaks things while using it plain on other pages causes no issues?
Update: i found out that when the RequiredFieldValidation is broken i can still trigger the errortext by filling and emptying the textbox on the clientside. the problem that the page validation on client side and on server side doesnt work correctly persists
Found out the problem after some extensive digging. I was using ASP:Linkbuttons inside the footer template which didn't do the validation anymore after the UpdatePanel surrouning everything did an update. Even though i used ChildrenAsTriggers="False" on my UpdatePanels it somehow messed up the clientside validation triggers.
I went and moved the buttons into the templates themselves and changed them into ASP:Buttons. I believe i needed the buttons to be Linkbuttons since the normal Buttons wouldn't trigger postbacks with the FormView_ItemUpdating and FormView_ItemInserting events of the Formview in the Footer template, but now that i have dedicated buttons inside the Insert and Edit templates they can be normal Buttons again.
Hope this helps someone out there facing a simular problems.

Telerik RadControls RadFormDecorator - Tow Problem About Positioning

i am using asp.net with c# web app in vs 2008
problem 1:
i do not know why Telerik RadControls- RadFormDecorator Moves some controls (such as Buttons or chech boxes) and changes their positioning up or down in my form after viewing in browser...
i put those controls in a cell of a table ... but not help
i had this problem about radajaxmanager and by setting UpdatePanelsRenderMode property to inline problem solved - but here there is no property like that...
what is going on here?
problem2:
i decorated my buttons and chechboxes with radformdecorator (telerik radcontrols) control...
when i click on a checkbox to set it to true or false so my webpage positioning goes to up (like when postback occurs , but this is not postback)
how can i prevent this problem ?
thanks for attention
This happens in some scenarios because of the way RadFormDecorator styles checkboxes - real checkboxes are hidden outside of the viewport. When the decorated checkbox is clicked however, browsers try to focus the real checkbox, hence the "jumping". To avoid that, you should set position:relative to the parent container.

Wrong state in Server Controls with same ID's when dynamically adding UserControl to UpdatePanel

Here is what I am trying to do. I have a page with two link buttons and an updatepanel (the two linkbuttons trigger the updatepanel). I have two usercontrols which have labels with same ID's. When I click the first link button, I add the first usercontrol to the updatepanel and set the label value to datetime.now
when i click the second link button i add the second usercontrol but i see that the value of the label from the first control is set in the label in second user control. if the id's are different there is no problem - but in my case the usercontrols are being developed by different teams and I am integrating them in the way i mentioned - so they may have same ids.
i have browsed all over and tried various suggestions but i cannot get this to work, any help will be greatly appreciated.
Thanks
Job Samuel
Your problem has nothing to do with the UpdatePanel, actually.
Imagine what would happen if you had a 3rd LinkButton, which did nothing but postback. What would happen if you clicked the 1st LinkButton, the UserControl appeared, and then you clicked the 3rd one? What do you expect to see? If you think you will see the UserControl again, you are wrong. Dynamically created controls must be created every request, they don't stick around automatically. ViewState remembers the state of controls on the page, NOT what the controls themselves are in the first place -- thats what the markup in the aspx page does. Dynamically created controls obviously arent in the markup, so they arent automatically recreated.
You need to think of the lifecycle of a control as 'straddling' half way between two requests. It starts half way into one request and ends half way into the next. You need to save which user control is currently displayed in either a hidden field or a Page.ViewState value (not the user control itself mind you, just whatever information you need to figure it out), then reload that control from the page's OnLoad. If you do that -- the sequence will go like this:
(1) Click LinkButton1
(2) UserControl1 dynamically created
(3) Click LinkButton2
(4) Page.OnLoad reloads UserControl1
(5) UserControl1 loads its postback data and viewstate
(6) LinkButton2's click event fires
(7) Remove existing UserControl1 and add UserControl2 dynamically
(8) UserControl2 can have the same ID, since UserControl1 already 'consumed' its state.
I suggest you browse my series of articles on Understanding Dynamic Controls in ASP.NET:
http://weblogs.asp.net/infinitiesloop/
You have to set a different id for the label when you create the user control.

UpdatePanel in Repeater

I have a UserControl which contains voting buttons inside an UpdatePanel, and outside a Repeater, it works perfectly. In the repeater, clicking the button fires off the appropriate event. That event is supposed to update the text of a control within the User Control, and that update should be reflected when the UpdatePanel refreshes.
If tried the UpdatePanel in UpdateMode Always and Conditional (firing the Update event after making the changes to the properties in the _Click method, and the same problem happens both ways.
Is there something about how UpdatePanels behave in Repeaters that I'm missing?
Thanks.
The reason might have nothing to do with the update panel, but with the postback loosing track of your UserControl. Possibly assigning unique IDs to your user controls may help.
Your repeater is building a table correct? The problem is most likely that an update panel generates a div tag and it's probably outside any TR and TD tags so the browser doesn't know what to do with it.
http://www.netortech.com/blog/?articleid=8

Using Page.IsPostback Within a User Control Wrapped in an Update Panel

I have a main page into which i load a user control with a grid and add/edit link buttons.
If I bind the grid by setting the datasource and calling the databind() method in the page load event then it sets properly. However, I want to keep the selected row between postbacks, so I wrap the bind code in "if (!Page.IsPostBack) {}" as usual. My problem is the page load always registers it as a postback and my code never runs.
I am using the 2.0 framework, and my grid is an 2008.1 Infragistics for the 2.0 framework.
I thinking this must be something simple.... or hoping anyway!
Thanks in advance
If you place your control into an UpdatePanel, then you should check for Page.IsCallback instead of Page.IsPostBack.
The two ways I found round this were:
to load the user controls when the page is first loaded and then hide them until user selected what they need to see.
to load a new page into an iframe on the main page allowing it to have its own page control meaning when its loaded in at first its not a postback.
Not the greatest, but gets by.
Thanks for the help.
I have mixed feelings about necroing a thread this old, but the question is still relevant, and there weren't any great solutions offered, so though I would add what I recently did to solve the same issue:
I had a similar problem with a site I was building. My solution was to add a method to the user control called "OnFirstLoad" that does all of the stuff I would have wrapped in an "if not Page.IsPostback" block. I then call the "OnFirstLoad" method from the hosting page the first time the control is loaded into the control tree. This way the control itself doesn't have to worry about whether or not this is a postback, and the main page can initialize it as needed.

Categories

Resources