Showing posts with label loaded. Show all posts
Showing posts with label loaded. Show all posts

Monday, March 26, 2012

UpdatePanel + Infragistics Treeview

I am trying to create a very simple UpdatePanel + Treeview page. The data is initally loaded (via code, recursive nodes added in code behind) the tree loads fine.

As soon as I click on a node (and capture the NodeClick event) the Tree view stops working and reports a Javascript error. "Microsoft JScript runtime error: 'undefined' is null or not an object"

Has anyone seen this before? Do the Infragistic controls not work with Atlas?

Thanks in advance.

Are you using the Tree's Automatic SmartCallback LoadOnDemand behavior, or Manual LoadOnDemand? I would recommend using the Tree's own AJAX enabled LoadOnDemand functionality, even inside of the UpdatePanel, since you really only need to update the tree. If you still have difficulty, please contact Infragistics Developer Support (http://devcenter.infragistics.com)

Also, if you have a valid Subscription, we are about to release our 2006 Volume 2 Beta. We've made some changes in order to better support Atlas, and it would be great if you could validate whether it fixes your current problems or not.

-Tony

Anthony Lombardo
Infragistics, Inc.
Product Manager | NetAdvantageASP.NET

Saturday, March 24, 2012

UpdatePanel and dynamically loaded webusercontrols

Hi,

This is my scenario, I'm can't figure out why the UpdatePanel doesn't update on a child control event.

I have a WebUserControl MyUserControl.ascx that looks like this:

1<asp:UpdatePanel ID="upnlMain" runat="server" ChildrenAsTriggers="True" UpdateMode="Conditional">
2 <ContentTemplate>
3 <asp:Panel ID="pnlContainer" runat="server">
4 </asp:Panel>
5 <asp:Label ID="lblTest" runat="server" Text=""></asp:Label>
6 </ContentTemplate>
7</asp:UpdatePanel>
In code behind I'm dynamically loading a dropdownbox as follows:
 
1protected void Page_Load(object sender, EventArgs e)
2 {
3 DropDownList ddl =new DropDownList();
4 ddl.Items.Add(new ListItem("aaa","aaa"));
5 ddl.Items.Add(new ListItem("bbb","bbb"));
6 ddl.Items.Add(new ListItem("ccc","ccc"));
7 ddl.AutoPostBack =true;
8 ddl.SelectedIndexChanged +=new EventHandler(ddl_SelectedIndexChanged);
9this.pnlContainer.Controls.Add(ddl);
10 }
1112void ddl_SelectedIndexChanged(object sender, EventArgs e)
13 {
14this.lblTest.Text = ((DropDownList)sender).SelectedItem.Text;
15 }
In my Default.aspx web page I have one single palceholder:
1<asp:PlaceHolder ID="phHolder" runat="server"></asp:PlaceHolder>
The idea is to load MyUserControl.ascx web user control dynamically into the placeholder, making sure the UpdatePanel of the user controls gets updated on dropdown list event.
 I'm adding this WebUserControl:
 
1protected void Page_Load(object sender, EventArgs e)
2 {
3 UserControl control = (UserControl)LoadControl("~\\MyUserControl.ascx");
4 controlElement.ID ="MyControl";
5 controlElement.EnableViewState =true;
6this.phHolder.Controls.Add(control);
7 }
  Everything works fine except the the updatepanel's update, for some reason, unknown to me, the drowpdown list does a full postback, ignoring the updatepanel that contains it. I'm not sure if I am doing something wrong or what I'm trying to achieve is not doable.
Any help is greatly appreciated.
Thanks,
 Virgil 
 
 


Hi virgilhretcanu,

In the UserControl you need to add the "ddl_SelectedIndexChanged" event to the updatePanel's Trigger Collection. Try like this:

protectedvoid Page_Load(object sender,EventArgs e)

{

DropDownList ddl =newDropDownList();

ddl.ID ="ddl1";

ddl.Items.Add(newListItem("aaa","aaa"));

ddl.Items.Add(newListItem("bbb","bbb"));

ddl.Items.Add(newListItem("ccc","ccc"));

ddl.AutoPostBack =true;

ddl.SelectedIndexChanged +=newEventHandler(ddl_SelectedIndexChanged);

this.pnlContainer.Controls.Add(ddl);

AsyncPostBackTrigger trigger =newAsyncPostBackTrigger();

trigger.ControlID = ddl.ID;

trigger.EventName ="SelectedIndexChanged";this.upnlMain.Triggers.Add(trigger);

}

void ddl_SelectedIndexChanged(object sender,EventArgs e)

{

this.lblTest.Text = ((DropDownList)sender).SelectedItem.Text;

}

Hope this will help you.

Thanks & Regards,

Rajak Shaik.

// Please Mark as Answer if this post helps you.


It works like a charm. Thank you very much Rajak

UpdatePanel and Dynamically loaded controls (LoadControl)

Ok so this has been doing my head in for nearly 3 hours straight. Everytime I think I found a piece of code that could solve this problem, adapt it and try it... well I always get the same darn result.

Here's the structure
MasterPage
Page
TabContainer + TabPanel (AJAX)
UpdatePanel (in a tabpanel)
UserControl containing a second user control

I keep telling myself I may have gone crazy trying to work with such a structure, but i have to load a different part depending on the current page, but the base stays the same (so thats why I have imbricated usercontrols). I use LoadControl() at pageload to load the correct control.

Now on to the problem: The second user control (mainly consisting of a gridview, so I'll call it the grid control) disappears when I generate a postback from within itselft (like clicking on a link in the button column). If I generate a postback from the parent control, however, it works just fine. I tried a bunch of things, liek using the viewstate to reload the control, to no avail. I thought maybe it was my control structure that would be the problem, so I made a test user control with just a button called click. Same thing happens.

In debug, I realized that the gridcontrol's page_load event was never called when I generated a postback from itself. So i went radical and added an updatepanel around the page content. Seems to fix the issue, but I don't really want the events of that part of the page to be independant from the rest... Cuz some buttons on the parent user control are supposed to cause the data displayed in the gridcontrol to change. And unless I can set triggers from the parent control, which I don't really know how to do if it's possible, well it's not really useful.

I'd appreciate any input on this, I could post my code but I don't really think it'd be that useful, and I hope I've been clear anough.

Thanks for your time

Try registering programmatically the controls from your Grid Control to execute an async postback:

ScriptManager1.RegisterAsyncPostBackControl(control);


Wednesday, March 21, 2012

UpdatePanel and OnBlur

Background: I have a script which attaches event listeners to OnFocus and OnBlur of my form controls after the page has loaded. The script updates a DIV with information about the element when focused and resets the DIV when blurred. My controls are wrapped inside an UpdatePanel.

The Problem: After the AsyncPostBack has occured my event listeners no longer work. The page is meant to redirect if all the fields are valid, so I am using validators - if the page is invalid it will not redirect and it is at this point that the event listeners stop working.

The Questions: Why are my event listeners not working after the AsyncPostBack? Is there a way to permanently register an event listener?

Also, now that I think about it... Are my validators overwriting the events? The validators only do custom server-side validation, no client-side.

how did you add the javascript to your controls?
like so:
textbox1.attributes.add("onblur","checkme(self);"); ?

could you perhaps post some more code?


I'm using javascript to gather all my form fields and add the listeners through the javascript. This works just fine, my code executes correctly. The problem is right after an AsyncPostBack.

My javascript load:

var fh = new formHelper();
fh.form = 'fm'; // Starting element
fh.divDisplay = 'divNote'; // DIV to display info
fh.helpForm(); // Load the event handlers

This is what adds the event handlers (this uses Prototype)

// Add event handler
if (elementsFound[x].title.length > 0) {
Event.observe(elementsFound[x], 'focus', this.getElementNote.bindAsEventListener(this));
Event.observe(elementsFound[x], 'blur', this.getElementNote.bindAsEventListener(this));
}

Everything works until the AsyncPostBack. My update panel is set to conditional and trigger is set to my btnSubmit.Click


I see..I had the exact same problem, but couldnt get it to work..
check here, perhaps it does help you:http://forums.asp.net/thread/1545416.aspx

if not I suggest you attach the javascript code via the attributes.add method..(if possble)

HTH

I managed to find a way to accomplish it.

In my btnSubmit_Click before I do the page.isValid check I re-register the script through the ScriptManager:

ScriptManager.RegisterStartupScript(btnSubmit, Page.GetType(),"fh", _ "var fh = new formHelper();fh.form ='fm';fh.divDisplay = 'divNote';fh.helpForm();", _True)
Thanks for helping me get started in the right direction