Showing posts with label content. Show all posts
Showing posts with label content. Show all posts

Wednesday, March 28, 2012

tree view + no postback + update panel

setup:

master page - content page layout

On my content page I want two update panels, one to contain a tree view dynamically generated from a database and the other to contain dynamically generated data (also pulled from a database) based on what is selected in the tree view. It is my understanding that tree view cannot be in an update panel. What is the best strategy for accomplishing this? I don't want a postback to be performed when an item is selected in the tree view. In other words, I don't want the entire page (form) refreshed just because an item in the tree view is selected.

Thanks in advance for any help.

If your treeview doesn't change the contents after the PageLoad, you may be able to have it in an update panel. We found that it doesn't work well if you add nodes to the treeview when you click a parent node, but if you load the full treeview it may be ok. If you need to dynamically add nodes as you click, you would probably need something like the TreeView that telerik has. We were looking at that one until we decided to do our page differently, and that control is not free, but seems to work nice.

The 2nd update panel would have a grid view in it. From the grid view I would add or edit content. If I added content the tree view would need to be refreshed without a full page postback to display the newly added item.

From the sounds of it, this isn't possible with strictly MS controls at the moment.


I just finished this very thing. The page starts with just a pulldown and then based on that value creates a Treeview dynamically without refreshing the page. Then clicking on a node causes another update panel to refresh with specific information.

Pretty convoluted with half Telerik and half MS. The full Telerik approach (Treeview and Update panel) looks easier, but we are using MS AJAX.

My older version of the Treeview (5.3) does not work with MS update panel, so I need to upgrade. I'm not too happy about it, but it seems to work well.

WISH LIST: A direct JavaScript method to postback to an MS update panel. As it is this seems to be the best approach:

http://forums.asp.net/thread/1541012.aspx


I followed the instructions on that thread and I have my update panel refreshing from javascript code. How do I call a javascript function when a tree node is clicked?

in the Telerik Treeview there is a property called "onBeforeNodeClick" and you can set that to the name of a javaScript function to fire when a node is clicked and before postback.


So, I did

myTreeNode.NavigateUrl ="javascript:postBackHiddenField('hardcodedhiddenfieldcontrol','" + uniqueIdentifierOfTreeNode +"')"function postBackHiddenField(hiddenFieldID, clickedID){alert("works");var hiddenField = $get(hiddenFieldID);__doPostBack(hiddenFieldID,'');}
 
I want to use the uniqueIdentifierOfTreeNode in order to modify the select paramter of a gridview in the update panel I'm refreshing from __doPostBack. I have no idea. Any help is appreciated. Is this the best approach to take even?

I forgot to mention the postback and refresh of the update panel is working as I have a label refreshed with the system time.
Nevermind, it looks like I came up with a reasonable solution that works.

Monday, March 26, 2012

Trigger for Update Panel with Multiple Content Sections on Master Page

Can I use an UpdatePanel in one Content section on a content page with a trigger in another Content section of the same content page?

I have a master page with multiple ContentPlaceHolders which I am using as the template for various pages with a search section and a results section. The search section is contained in one ContentPlaceHolder and the results is contained in another. The content page search section contains an ASP.NET button control (id="btnSubmit") and the content page results section contains an Atlas UpdatePanel containing a Trigger which I would like to tie to btnSubmit. I have tried declaratively to make btnSubmit the trigger, as well as programmatically. When the page loads, I get a "ControlID of trigger must reference valid control" error either way. I have tried substituting btnSubmit.ClientID.ToString inside the trigger definition and this does not work either.

I have another master page/content page combination where both the trigger and the update panel are in the same ContentPlaceHolder/Content section, and I have no problem getting Atlas to work. I am using the April CTP of Atlas.I made a similiar post... I hope I will get a replyhttp://forums.asp.net/1450493/ShowThread.aspx#1450493 from here

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

triggering an export of Excel content through Atlas

I built an Atlas-enabled form. Depending on an input parameter, I need to either display the output data in HTML or push an Excel stream to the browser. The former is accomplished beautifully with the UpdatePanel; however, I am struggling to figure out the latter. The folowing code works as desired (it results in the browser opening the "File Download" dialogue that allows users to Save or Open the file) with the "regular" postback:

 Response.ContentType ="application/xls"; Response.AddHeader("content-disposition", GetExportFileName("Excel")); XlsExport xls =new XlsExport(); xls.Export(report.Document, memStream); Response.BinaryWrite(memStream.ToArray()); Response.End()

What do I need to do to accomplish this behavior with Atlas?

Thanks a lot!

hello.

can you do that on an external window? ex.: a button click opens a window which targets a handler that returns the response you've shown in the previous post...


Unfortunately, I am not allowed to open an external window.

I was allowed to implement the obvious workaround: save Excel file to disk, put another UpdatePanel on this page, and then display the download link once the file becomes available; however I would rather avoid having to maintain hard copies of the files...


How about an IFRAME with the Excel content type?


I must admit my ignorance: I have not worked with IFrames before. I started reading just now, and it looks like it might be a good solution - if there is a way to close the IFRAME once the user sees the "Save as/Open" dialogue. I will research this further...

If you know of a good working sample online, please let me know.

Thanks a lot!


hello.

hum...i think you're in luck since you can set the src dinamically and event its display is set to none, you'll have the downlod. test this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<iframe id="frm" style="display: none"></iframe>
<hr />
<input type="button" value="donwload" onclick="download()" />

<script type="text/javascript">
function download()
{
document.getElementById("frm").src = "eula.rtf";
}
</script>
</body>
</html>


I am sorry it took me a while to reply - I am in the final stretch of a project...

I managed to build a prototype based on Luis' suggestion; however, there is one problem with this approach: if a user clicks on "Open" button of the "Save as/Open" IE dialogue, then the file may open not in a new instance of the Excel, but in the transparent iframe - and hence be invisible to the user. This wouldn't be an issue had the response been written to a new browser window instead of the iframe, but in my case it wasn't an option.

In the end I simply ran out of time to play around and put in the workaround I described a couple of posts ago.

Thanks a lot for everybody's help!

Triggering Update Panel from Dynamically Built Triggers

I have a page which has two content areas (Left, Center). The Left hand content contains two repeaters, both of which have an imagebutton who's itemcommand triggers an update of the content in the Center area. The Center Area has an update panel in it. The triggers are dynamically generated because the repeaters are in panels, and I needed to use the findcontrol() command to get access to them.

Code works great on my laptop (localhost), gives an error when I move it to the server. Error is:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing this request on the server. The status code returned from the server was: 500.

Here's my UpdatePanel:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Repeater ID="rMain" DataSourceID="srcMain" OnItemCommand="rmain_itemCommand" runat="server"> <ItemTemplate> <asp:Label ID="lblTitle" Text='<%#Eval("Description")%>' runat="server" CssClass="verorangeHeader" /><asp:Label ID="ProductID" runat="server" Text='<%# Eval("idProduct") %>' Visible="false"></asp:Label><asp:Label ID="lblSKU" runat="server" Text='<%# Eval("Sku") %>' Visible="False" /><br /><br /> <table border="0" cellpadding="1" cellspacing="1"> <tr> <td > <asp:Label ID="lblDetails" Text='<%#Eval("Details")%>' runat="server" CssClass="ver11bluebold" /> </td> <td ><img src='<%# formatPhoto(Eval("ImageURL")) %>' /></td> </tr> <tr> <td colspan="2" align="right" valign="top">Priced from: <asp:Label ID="lblPrice" Text='<%# formatPrice(Eval("Price")) %>' runat="server" CssClass="verorange" />   <asp:ImageButton ID="btnSpecifications" ImageURL="images/btn_specifications.gif" runat="server" /><asp:ImageButton ID="btnPhotoGallery" ImageURL="images/btn_photo-gallery.gif" runat="server" /><asp:ImageButton ID="btnBuyNow" ImageURL="images/buy-bm-clear.gif" runat="server" CommandName="Update" /></td> </tr> </table></ItemTemplate></asp:Repeater></ContentTemplate></asp:UpdatePanel>

Here's the code that creates the triggers:

Private Sub Page_Init(ByVal senderAs Object,ByVal eAs EventArgs)Handles MyBase.Init'Add TriggersDim ap1As AsyncPostBackTrigger =New AsyncPostBackTrigger()Dim ap2As AsyncPostBackTrigger =New AsyncPostBackTrigger() ap1.ControlID = pnlProduct1.FindControl("rY5").UniqueID ap1.EventName ="ItemCommand" ap2.ControlID = pnlProduct2.FindControl("r52").UniqueID ap2.EventName ="ItemCommand" UpdatePanel1.Triggers.Add(ap1) UpdatePanel1.Triggers.Add(ap2)End Sub

Any suggestions?

Jennifer

Take a look at this post...http://forums.asp.net/p/1139950/1831145.aspx

-Damien


Got it fixed. It was actually related to a bug in my Master Page!

Thanks for the help!

Jennifer


To fix this problem, you can add the follow code in your web.config

<system.web>
<pages validateRequest="false">
</system.web>.

Triggers Across Content Control

I've seen this posted a few times but no concrete solution or identification of the problem. I have 2 content section. The first one has buttons that should trigger an update in the second content. The second content has an UpdatePanel with the trigger definition. But I get the following error:

The ControlID property of the trigger must reference a valid control.

This is the code:

<

asp:ContentID="Content3"ContentPlaceHolderID="MainContentHeaderHolder"Runat="Server">
<strong>Property Details :: Options</strong>
<div>
<asp:ButtonID="btnNewResident"Text="[New Resident]"OnClick="ViewResidentPanel"runat="server"/>
</div>
</asp:Content>
<asp:ContentID="Content4"ContentPlaceHolderID="MainContentHolder"Runat="Server">
<atlas:UpdatePanelID="upNewRecordPanels"runat="Server">
<ContentTemplate>
......
</ContentTemplate>
<Triggers>
<atlas:ControlEventTriggerControlID="btnNewResident"EventName="Click"/>
<atlas:ControlEventTriggerControlID="btnNewContactNumber"EventName="Click"/>
<atlas:ControlEventTriggerControlID="btnNewAuthorizedGuest"EventName="Click"/>
</Triggers>
</atlas:UpdatePanel>
</asp:Content>

Is there a solution or is this a bug or by design?

{Bump}

Any thoughts from anyone on this? Is it by design that you cannot cross content sections or does it need to be done a different way?


Hi
I bumped into the same problem. It makes some kind of sense, because the controls in the other content control will be loaded in a different container and from what I've seen the UpdatePanel cannot find it.
One solution would be to edit the control id to its UniqueID:
<atlas:ControlEventTriggerControlID="MainContentHeaderHolder$btnNewResident"EventName="Click"/>
or
<atlas:ControlEventTriggerControlID="ctl00$MainContentHeaderHolder$btnNewResident"EventName="Click"/>

In both cases the error disappears, but i didn't test if the trigger gets fired. An alternative would be to add the trigger from the code using the UniqueId (easier if you later need to modify the control herarchy).

Anther solution (the one i used) would be to relate the trigger to a control that gets changed inside the UpdatePanel, like a panel.Visible - you probably have one that changes, otherwise you wouldn't need to update it. Although the controls inside the content template of the update panel do not appear as choices in the designer, you can add the trigger manually in source view.

I hope this helps
Vlad