Showing posts with label head. Show all posts
Showing posts with label head. Show all posts

Saturday, March 24, 2012

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 Javascript - Preload Images?

Im having a problem,

When i use the following javascript in the <head runat="server">... other head items..

<

SCRIPTtype="text/javascript"LANGUAGE="JavaScript">

<!-- Begin
image1 =

new Image();

image1.src =

"/images/header.jpg";

// End -->

</script>

</head>

That code seems to break the timer and updatepanel. Any ideas? I see no errors on the client side, except that it doesnt update on the interval I've chosen, but when i remove the preloader code it works. ?!? Anyone have work arounds?

Try putting the script in an external .js file and reference that file in the scriptmanager:

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering=true>

<Scripts><atlas:ScriptReferencePath="/inc/helperscripts.js"/></Scripts></atlas:ScriptManager>

philmccracken:

Try putting the script in an external .js file and reference that file in the scriptmanager:

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering=true>

<Scripts><atlas:ScriptReferencePath="/inc/helperscripts.js"/></Scripts></atlas:ScriptManager>

Hmm, I do that and now I get object not found error in IE. (line 2,123 something..) I see the correct reference in the HTML output. If you wish to check that implementation its onwww.smackfm.com, perhaps Im using wrong way to implement Preloading of images and its causing the timer to break?


Can you run javascript on the fly in an external script file? (I don't know, I've never tried). Maybe you need to put that inside a function and then run the function? Either by adding an onload to the body tag, or maybe with page.registerstartupscript? I'd play around with it... (Unless someone wants to post that knows for sure...)


try thisDevil [666]
<script type="text\javascript"> var img = new Image(); img.src = "/images/header.jpg";</script>