Showing posts with label panels. Show all posts
Showing posts with label panels. 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 not working for Linkbutton in GridView

I have a linkbutton I'm trying to add a trigger two for two update panels on my aspx page.

I have this but the update panels are not updating... any recommendations?

protected void GridView_ChangeSearchResults_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lb = (LinkButton)e.Row.FindControl("Linkbtn_StaffChangeNew"); AsyncPostBackTrigger trigger =new AsyncPostBackTrigger(); trigger.ControlID = lb.UniqueID.ToString(); trigger.EventName ="Command"; UpdatePanel_Header.Triggers.Add(trigger); UpdatePanel_Info.Triggers.Add(trigger); } }

It doesn't bomb out on me and I've put in a breakpoint and is seems to be adding the triggers but they don't fire for some reason. When I add the triggers in from the GUI I'm using the onlcick event for other button controls on the page.

For this action I am using a command event. I've tried changing the EventName to both Click and Command and neither seem to work. Here is the method for the command event.

protected void ChangeStaffFromGrid(object sender, CommandEventArgs e) {int userStaffID = Convert.ToInt32(bmsUser.CmsStaffID);string budgetyear = Convert.ToString(budgetYear.UserSelectedFiscalYear);
int profileID = Convert.ToInt32(Session["staffProfileID"]);int newProfileID = 0;int newStaffID = Convert.ToInt32(e.CommandArgument);//sets the new staff ID from the selection. Hashtable changeStaffHash =new Hashtable(); changeStaffHash = BmsDLL.ChangeStaff(profileID, newStaffID, userStaffID); newProfileID = Convert.ToInt32(changeStaffHash["newStaffProfileID"]); SetUserSessions("change", newProfileID); SetHeaderInfo(Convert.ToInt32(Session["staffProfileID"])); SetNewProfileIDItems(Convert.ToInt32(Session["staffProfileID"])); }

The two methods that update the two pannels are SetHeaderInfo and SetUserSessions.

Thanks for your help.

Use ScriptManager1.RegisterAsyncPostBackControl(YourLinkButton) instead of creating AsyncTrigger. then in the button command event update your update panels by calling the update.


I've just recenlty started using Ajax in my app, do you have a code example of your suggestion?

Which even would I add ScriptManager1.RegisterAsyncPostBackControl(YourLinkButton) ? In the rowdatabound event?


Try the following code:

protected void GridView_ChangeSearchResults_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lb = (LinkButton)e.Row.FindControl("Linkbtn_StaffChangeNew");ScriptManager1.RegisterAsyncPostBackControl(lb);// Assuming the ScriptManager name in your page is ScriptManager1 }}

That didn't work. The same updates to the panels are working with regular buttons. This makes no sense.


Hi,

As far as I know,You can add anUpdatePanel control programmatically, but you cannot add triggers programmatically. To create trigger-like behavior, you can register a control on the page as an asynchronous postback control. You do this by calling theRegisterAsyncPostBackControl(Control) method of theScriptManager control. You can then create an event handler that runs in response to the asynchronous postback, and in the handler, call theUpdate() method of theUpdatePanel control.

For more information,seehttp://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_UpdatePanel.aspx

IfRegisterAsyncPostBackControl(Control) method & Update() method doesn't work, there must be something wrong in your code.You can post some code so we can check out where is the error.

Best Regards


It seems the Update() method is working for me. Thanks for your help.

Saturday, March 24, 2012

Trigger Update Panel from button on different ContentPanel

I have a master page with two contet panels: cntSearch and cntBody. The cntSearch panel has a search form and a button (btnSubmit), the cntBody panel, among other things, has an Update Panel which contains a gridview (grdMain). I am trying to set up a trigger between the submit button in the cntSearch panel and the gridview in the cntBody. Visual Studio 2005 IDE allows me to pick btnSubmit and its Click() event from the list of possible controls when I go and add a Trigger to the Update Panel. However, when I try to load the page I get an error indicating that "A control with ID "btnSubmit" could not be found for the trigger in UpdatePanel..."

When I move the button from the cntSearch Content Panel inside the cntBody Content Panel, the page loads fine. Is there a special way I need to reference the button's ID in the Trigger section of the Update Panel so that it can find it?

Thanks,

Jaime

Here is a simplified version of my code:

<%

@.PageLanguage="VB"MasterPageFile="~/Master.master"AutoEventWireup="false"CodeFile="test.aspx.vb"Inherits="test"title="Untitled Page" %>

<

asp:ContentID="ctSearch"ContentPlaceHolderID="cphSearch"Runat="Server"><asp:ButtonID="btnSearch"runat="server"Text="Search"/>

</

asp:Content>

<

asp:ContentID="ctBody"ContentPlaceHolderID="cphBody"Runat="Server"><asp:UpdatePanelid="upMain"runat="server"><contenttemplate><asp:GridViewid="grdGrid"runat="server"></asp:GridView></contenttemplate><triggers><asp:AsyncPostBackTriggerControlID="btnSearch"EventName="Click"></asp:AsyncPostBackTrigger></triggers></asp:UpdatePanel>

</

asp:Content>

Thanks,

Jaime


This is from my another post:

I have solved my problem by doing the following..

Iwrapped my 2 content areas in the master page in a update panel.Basically I put the content panes inside an update panel in the masterpage. Now on my other page, if I click on a button in one content area,both the contents get updated without the page being refreshed.

Thanks



Thanks for the reply marathi. I tried your suggesting and it did not work, I am still getting the error indicating that the submit button can not be found.

Jaime


Can you post your source here. I shall look into it, it works fine for me.


Thanks to marathi for putting me on the right track since no final post was here I thought I would add my derived solution. Basically if you place the UpdatePanel control in the master page and aroundboth content panels you can still place the Trigger in the child page where the triggering control is defined. My own use was to have a calendar in the first content section change the content in the second content frame (a custom control) and it works great.

In your master page: 
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ContentPlaceHolder ID="cntSearch" runat="server"></asp:ContentPlaceHolder><asp:ContentPlaceHolder ID="cntBody" runat="server"></asp:ContentPlaceHolder> </ContentTemplate></asp:UpdatePanel>
 In your child page:
  
<asp:Content ID="cntSearchContent" ContentPlaceHolderID="cntSearch" runat="server"><asp:TextBox runat="server" ID="SearchText"></asp:TextBox> <asp:Button ID="SearchButton" runat="server" Text="Search" /></asp:Content><asp:Content ID="cntBodyContent" ContentPlaceHolderID="cntBody" runat="server"> <asp:GridView ID="GridView1" runat="server"></asp:GridView><Triggers><asp:AsyncPostBackTrigger ControlID="SearchButton" EventName="Click" /></Triggers> </asp:Content>
 

Wednesday, March 21, 2012

trouble setting focus on a textbox after I put the panel in a updatepanel

My webpage was working fine setting focus properly on a textbox but after I put a few panels in an updatepanel the focus no longer works. I put two panels in the same updatepanel box, each one has a button click that goes and retrives some info. Everythng works fine except focus isnt being set. Im using c# in Visual Studio 2005 professional

how do you handle the focus of the textbox and in what event? usually you can set the focus using $get(textboxClientID) during the pageLoaded event of Sys.WebForms.PageRequestManager

hth


Are you using YourScriptManager.SetFocu(YourControl) ?


ScriptManager.SetFocus($get(textBox.ClietnId))

Let me know if this helpful to you

Trying to implement a thread queue for page with 6 update panels

I am attempting to write a FIFO thread queue for the dashboard portion of a portal application. There are 6 update panels that refresh independent of each other about every 60 seconds, so there are a lot of postback collisions and I need something to save postbacks and re-issue them when the callback from the prior async call is returned.

It looks like there has been quite a bit of effort put into this, but none of the code I could locate would work in my situation because of various "can't find id", "null reference", and "object does not have this function" -related js errors.

Here is what I have so far:
Sys.Application.add_load(ApplicationLoadHandler)

function ApplicationLoadHandler(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (!prm.get_isInAsyncPostBack())
{
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(CompleteRequest);
}
}
// initialize a queue
var myQueue = new Array();

function CompleteRequest(sender, args)
{
if(myQueue.length > 0)
{// fire correspond event again of the item cached
var control = $get(myQueue[0]);
setTimeout('__doPostBack(\'' + control.id + '\',\'\')', 0);
Array.removeAt(myQueue, 0);
}
}
function InitializeRequest(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();

if (prm.get_isInAsyncPostBack())
{
// if it's working on another request, cache the current item that cause the request
args.set_cancel(true);
Array.add(myQueue, args.get_postBackElement().id);
}
}

if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

Even if this did work, it wouldn't do what I want it to do because '__doPostBack(\'' + control.id + '\',\'\' would strip out all of the eventargs that were sent along with my postback (for instance, if the user initiated the postback via mouse click) and turn "doPostBack('gridviewSomething', 'Select$1')" into "doPostBack('gridviewSomething')", which is clearly no good.

This code will properly interrupt postbacks and save them to queue, but upon callback and re-initiation I get problems. Anyone have any suggestions? I feel like this is so close and I am loosing my hair over it, so help is much appreciated.

Merry (early) Christmas.

http://disturbedbuddha.wordpress.com/2007/12/12/handling-multiple-asynchronous-postbacks/