Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
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)
    PlaceHolder1.Controls.Clear()
    PlaceHolder1.Controls.Add(LoadControl(myControl))
 End Sub
Thanks in advance.
 
Enan
Posted 29-Sep-12 8:09am
Edited 29-Sep-12 8:43am
(no name)105.8K
v2
Comments
Sandeep Mewara at 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 at 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 at 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 at 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 at 29-Sep-12 15:28pm
   
Strange. May be caching issue. You sure that alerts are different. Right?
Hernan K. Cabrera at 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 at 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
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2014
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