Click here to Skip to main content
12,547,214 members (64,085 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET

I'm dynamically loading .ascx in a placeholder inside .aspx
and the placeholder was inside ajax updatepanel.

I have 2 .ascx, when I load the first .ascx then I can execute the javascript inside that ascx. But when I load the 2nd .ascx, it still reads the javascript of the first .ascx, Why is that behaving like that? Can somebody help me how to do it right.

This is how i load the .ascx
Sub loadUserControl(ByVal myControl As String)
End Sub
Thanks in advance.

Posted 29-Sep-12 7:09am
Updated 29-Sep-12 7:43am
Sandeep Mewara 29-Sep-12 14:15pm
Explain a little more: "it still reads the javascript of the first .ascx"

How do you know this?
Hernan K. Cabrera 29-Sep-12 14:57pm
Hi Sandeep,

I tried to execute function on onload. eq. alert('User Control 1') for the 1st ascx and alert('User Control 2') for the 2nd ascx with the same function name. Either of the two ascx giving me the same message "User Control 1".
Sandeep Mewara 29-Sep-12 15:17pm
Do a viewsource of your webpage and see what is there in HTML. Is UC1 still there?
Hernan K. Cabrera 29-Sep-12 15:23pm
Yes Sandeep, even if I click button that will load the 2nd ascx, I can still see the UC1 alert message function in the viewsource.

But when I tried to comment out the scriptmanager, updatepanel and contenttemplate, it runs correctly.
Sandeep Mewara 29-Sep-12 15:28pm
Strange. May be caching issue. You sure that alerts are different. Right?
Hernan K. Cabrera 29-Sep-12 15:36pm
Yes Sandeep, they are different. I've tried to make their function name different and the 2nd ascx give me error. Before, I don't have problem with this because I used response.redirect to refresh my usercontrol inside my main page but now I want to just refresh my usercontrol by simply loading the usercontrol in the placeholder.
Hernan K. Cabrera 30-Sep-12 16:45pm
Hi Sandeep,

I think my problem is due to partial-page rendering.

I added <postbacktrigger> after the contenttemplate then it works. So, meaning its the same now as response.redirect?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161018.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100