Showing posts with label partial. Show all posts
Showing posts with label partial. Show all posts

Wednesday, March 28, 2012

Trace="True" and partial postbacks

When a page is set to Trace="True", partial postback fail with an error stating that there is a problem parsing the page and the reason could be because Trace is set to True. OK, so how are we supposed to trace our pages then?

You can use Tracing but you can't use the pageouput option (so that the trace gets displayed on your webpage). That's causing the error. What you can do is set the page output to false.

<traceenabled="true"pageOutput="false"/>

If you want to view the tracelog, you can view it usingtrace.axd(http://somewebsite/trace.axd)

Monday, March 26, 2012

Trigger full postback from the server during a partial postback.

Well, I have a dialog user control (ajax popup) which can again contain other user asp user controls as content. The content of the dialog is created inside an UpdatePanel, so that the dialog content can postback. All of that works OK.

On the web page I have now some information visible inside a GridView which is not in an UpdatePanel and should not be, because I need the browser forward/backward button to work. A link on that web page lets one of these dialog controls pop up. The dialog contains a user control which can manipulate the data which is visible inside the GridView. If the user presses a button inside the dialog, the dialog does an asynchronous postback as the user control/dialog content is inside an update panel and the dialog closes. That gives the user the impression that nothing happened as the data visible in the GridView did not change. I do already have the code to refresh the gridview, but how can I change the behavior during the postback from being an asynchronous postback to a full postback?

So just to clarify some pseudo code:

In the user control contained inside the dialog I would have some code like:

void OnOK(...)
{
// check if any data changed
if (textBox.Text != record.Text)
{
// do a database update
// and
// update cached data which the datagrid is bound to
// call a method on the page to rebind the datagrid only

// ? Force a full page refresh
}
else
{
// do nothing
// asynchronous postback is OK, no full page refresh needed
}
}

The force of a full page refresh is what I would need. In a fat environment like Windows Forms, I would just call Invalidate on the Form. Or IF the DataGrid would be inside an UpdatePanel I would search for it and call Update() on it, but then I would loose the browser caching during back and forward movements. So I was searching through all of the classes if there is something like ScriptManager.UpdatePage or something similar, but have found nothing so far.

So what is the solution here? How can inform the ajax client side script, that it should just go ahead and rerender the whole page instead of just extracting the update panel portions?

Thanks

In the <Triggers> collection of your updatepanel, just add whatever control you want to cause a full refresh as a PostBackTrigger instead of as a AsynchPostBackTrigger.

<asp:UpdatePanel ...>
<Triggers>
<asp:PostBackTrigger ControlID="whateverID" />
</Triggers>
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>


Well, that does not work:

a) the UserControl is designed separatly and does not have an update panel and vice versa the dialog is a generic control which just adds a UserControl as a content, so it cannot hardcode if there is any control ID inside which should trigger a full postback

b) I do not want a full postback to occur all the time when the button is pressed, the logic of the button on the server side should determine if a full postback is necessary or not, if not then a partial postback is OK.


I tried to work around now, kind of using your approach by doing this in the OnPreRender or OnChildControlsCreated of the UserControl:

System.Web.UI.WebControls.WebControl btnOK =this.Parent.Parent.FindControl("btnOK")as System.Web.UI.WebControls.WebControl;
if (btnOK !=null)
{
System.Web.UI.Control control = btnOK;
UpdatePanel updatePanel = control.ParentasUpdatePanel;
while ((updatePanel ==null) && (control !=null))
{
control = control.Parent;
updatePanel = controlasUpdatePanel;
}
if (updatePanel !=null)
{
PostBackTrigger pbTrigger =newPostBackTrigger();
pbTrigger.ControlID ="btnOK";
updatePanel.Triggers.Add(pbTrigger);
}
}

So I do find the OK button and I do find the UpdatePanel that contains the button, but it has no effect whatsoever.
The control ID must be right, otherwise I would not be able to find the button with it, but still no PostBack and the Dialog itself is not inside an UpdatePanel.

Saturday, March 24, 2012

Trigger partial page update from child window... or from DIVed IFrame

Hello there.

I need ideas on how to trigger an update panel from a child window (window.open) with ASP.NET AJAX. How can I access the "parents" page Scriptmanager or even the UpdatePanel itself?

The other possible option would be to do a callback from an IFrame but I am also unsure if it is possible to tweak it in such a way that only certain parts of the page are reloaded.

If you have already accomplished this in some way or the other than I would greatly appreciate if you share your solution or give some hints.


thanks,

Elmar

Gosh, isn′t it always like this - after posting the above I found a very decent solution for this issue. It does not involve hidden controls or similar.

In case you want to know more - here is thelink

Elmar

Triggering a Partial Postback with a Button Inside a Repeater

Hi All,

I have a Button inside a Repeater inside an Updatepanel and I would like to trigger the update of another updatepanel. The strategy I have utilized thus far is to add a commandname parameter to the button, passing it to the itemcommand parameter of the repeater. I then add a asyncpostback trigger for the 2nd updatepanel for repeater.itemcommand. The code that I have for the itemcommand executes, but the problem is I get a full page refresh. If anyone has a work around for this problem or know of a way to do something similar using a different strategy, I would greatly appreciate your help =) Thanks in advance!

I would also like to add that I have tried this with the repeater outside of the updatepanel and it still does not work.
While we work closely with the ASP.NET AJAX team when developing the Toolkit, they're the real experts on general ASP.NET AJAX issues. Your problem doesn't seem to be directly related to the Toolkit, so we'd appreciate if you considered posting to one of theother newsgroups such asAJAX Discussion and Suggestions. Your post will be more helpful to others looking for similar advice if it's in the right place. Thank you!

Triggering partial update on text box losing focus

Hi,

I have a form on which I want a user to be able to enter a post code and, when the user tabs out of the field, triggers the population of a drop down list which contains the suburbs the postcode relates to, so the user can then select the suburb.

I have the drop down list in an Update Panel with partial rendering turned on but I can't figure out how to trigger it being refreshed when the control loses focus. I think I need to link it to the OnBlur event using javascript but I'm stuck at that point. Any ideas appreciated...

Thanks,

SimonOK, it was me being dippy. I didn't need to get clever and start hooking client side events, I just needed to set the Render property to "Always" and it fires whenever the text box loses focus.

S