Javascript inside "web user control" not run if load "web user control" under ajax UpdatePanel

I have this problem and please if some can help me, I place here a sample code to see, but in my real problem the web user control have a very complicate javascript.

I have a web user control that have some javascript inside, let say for example.

1    <script type="text/javascript" >
2    	function RunMe()
3    	{
4    		alert("Client id:<%=ClientID%>");
5    	}	
6    </script>
7    
8    
9    <a href="javascript:RunMe()">Run javascript</a>

a simple call to a simple javascript, inside the web user control

And now I have a page that try to asyncronous load this control, let say...

1        <form id="form1" runat="server">
2        
3    	<asp:ScriptManager ID="ScriptManager1" runat="server"  >
4    	</asp:ScriptManager>
5        
6    	<asp:UpdatePanel ID="TestAjax" runat="server"  >
7    	<ContentTemplate>    
8        
9    		<asp:Panel ID="panelTest" runat="server" Visible="false">
10   			<uc1:ControlWithJavaScript ID="ControlWithJavaScript1" runat="server" />    
11   		</asp:Panel>
12      
13   	    <br />
14   		<asp:Button ID="Button1" runat="server" Text="Show panel" onclick="Button1_Click" />
15   	
16   	</ContentTemplate>
17   	</asp:UpdatePanel>
18       </form>

  Here is the code that open and close the web user control

1        protected void Button1_Click(object sender, EventArgs e)
2        {
3            panelTest.Visible ^= true;
4        }
5    

 

Now when I open and close the web user control I force to ajax load it inside the page, and the control is loaded, but the javascript is not run.

Can you help me and tell me how to solve this problem ?

Thank you in advanced. 

Aristos

ps - I have done my research on Internet and MSDN befoure I post it here, and I have found a solution, that is not what I search for, and not working under my real code.

The solution is to use this code on the web user control, but
is still missing a lot of thinks, like separate the javascript from the code
and render them seperate.


1    protected override void Render(HtmlTextWriter writer)
2        {
3            ScriptManager sm = ScriptManager.GetCurrent(Page);
4   
5            if (sm.IsInAsyncPostBack)
6            {
7                StringBuilder sb = new StringBuilder();
8   
9                base.Render(new HtmlTextWriter(new StringWriter(sb)));
10  
11               string script = sb.ToString();
12           
13            // need work here, to seperate the javascript from the html script
14            // but what about a complex code that have javascript, html code, then again javascript
15            //  and javascript inside html links etc....

16               ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, false);
17           }
18           else
19           {
20               base.Render(writer);
21           }
22       }
23  

0
mAristos
1/26/2008 11:02:52 AM
asp.net.ajax-ui 9760 articles. 0 followers. Follow

2 Replies
2992 Views

Similar Articles

[PageSpeed] 37

This is because normally, javascripts are not placed within the <HTML></HTML> Tags, and everything rendered in an update panel is, more or less, so the browser will see it as junk, and generate a script error (i.e. definition for RunMe not found). The best approach is as you said, to use the ScriptManager, and I find using a seperate .js file is a little easier, and you can call RegisterClientScriptInclude. I think you have to do it on PreRender though, not on Render.

0
valenumr
1/26/2008 11:58:27 AM

To place the javascript out side alone is not an option because the javascript is "generated" the moment I show the button.

Is a complicate control that I have create to select images, and manipulated on fly with out any post until the final "OK".

I use the Yahoo Ajax User Interface to open an inside window and select an image from local folder, then I use prototype and some javascript code to manipulate the image on the flight with out any post back, like change size, place watermark, cut it, rotate it, etc...

All that I do with javascript with a complicated code that have many variablems that I create on fly. Also this control can be used on the same page many times, and the javascript and some divs ids not hit the one the other.

If I load the code using prototype ajax, the javascript is loaded normal, but under asp.net ms ajax style, the loader not render the javscript and I am wondering if there is an easy think to do and tell it to load it as javascript.

By the way, if I remove the Ajax tags, all works ok, the control working good, and the aboce code work good if some one remove the ajax tags.

 

0
mAristos
1/26/2008 12:31:19 PM
Reply:

Similar Artilces:

Dynamically adding "Child" User Controls to "Parent" User Control
Hello group..Need some advice/help with some issue...Am having trouble dealing with nested user controls that i will be having. My business need is as follows...Need to display a Page Header , data Grid(for some details) and Page footer...And the grid will display only a set of data. If i have more data, the parent page should have another set of Page Header, data Grid and Page Footer. So, this is how it looks like***************************Page HeaderGridPage Footer--------Page Break---------Page HeaderGridPage Footer--------Page Break---------Page HeaderGridPage Footer--------Page Break---...

Inside a web user control ajaxToolkit:AutoCompleteExtender OnClientItemSelected="function" sends "function is undefined"
This is my code....consider that the code is inside a web user control... on a webform this works correctly <script type="text/javascript">function myItemSelectedHandler(source,eventArgs) {var add = document.getElementById('<%= addressTXT.ClientID %>'); showAddress(add); } </script> <asp:TextBox runat="server" ID="addressTXT" Width="300" /><ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoComplete1"BehaviorID="AutoCompleteEx" TargetControlID ="addressTXT" ...

"Write your own extender" example in AJAX Control Toolkit not working
I installed the Control Toolkit, then followed the instructions for the VB version of "write your own extender".Here's the URL of the directions from the toolkit: http://localhost:56850/SampleWebSite/Walkthrough/CreatingNewExtender.aspxI think that I installed everything correctly and followed all directions, but when I try to run the "DisableButton" sample, I get the following error: Extender control 'DisableButtonExtender1' cannot extend 'Button1'. Extender controls of type 'DisableButton.DisableButton.DisableButtonExtender' cannot extend controls of type 'System.Web.UI.WebControls.Bu...

How to programmatically access "Create User" button in CreateUserWizard control and "Log In" button in Login control?
Hello, How can I programmatically access "Create User" button in CreateUserWizard control? Also how can I programmatically access "Log In" button in Login control?  Improving lifestyles for luxury pets: TheFabulousPet Hi, here is the way in this example I change only the buttons text on page load (you didn't specify what property exactly want to access):Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Login1.LoginButtonText = "test" CreateUserWizard1.CreateUserButtonText = "test2" End ...

What are "web user controls" used for?
Hi all!!I'm new in this VS2005 stuff and I'm investigating a web site using Vs2005 and C#. I've read something about web user controls, but, what are they used for? What are the main advantages? What are the differences between web user controls and controls just added to my web form??Thanks in advance!!cu guys. Hi, and welcome to the ASP.NET forums. Web user controls, sometimes called pagelets, are small pieces of reusable code that you can quickly create and place upon several pages with drag & drop from the Solution Explorer. You can also load them dynamically if you want like any...

How to "parametize" Web User Controls
Hi, [VWD Express / C#] I have created a Web User Control for a common DropDownList in my application and would like to parametize parts of it. Here is the Code Behind (parts to be parametized in bold): public partial class WebUserControl : System.Web.UI.UserControl{  protected void Page_Load(object sender, EventArgs e)  {  }   protected void ddlAccounts_DataBound(object sender, EventArgs e)  {    if (Session["ddlAccounts"] == null)    {     //No account has been specified yet - we want the user to sel...

Controlling user access using "allow" "deny"
I have a web form application for deployment on Windows 2000 Server.  I wish to limit access to the web site to a certain group of users, all having accounts on the server.  The authentication mode is "Windows", impersonate ="true"...  From my reading, this seems the perfect situation to use "roles=" within the authentication block.  I must admit, however, that I am not a server admin guru.  What is a "role" in terms of 2000 server?  What sort of group, organizational unit, etc. would be created on the server to act as a "role"?  Any light shed would be app...

difference between "using System.Web.UI.WebControls" or "System.Web.UI.WebControls.ServerValidateEventArgs"
Hi all, quick question. I'm writing a custom validation method. In the declaration it has: protected void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) Is there any difference between doing that, vs doing: using System.Web.UI.WebControls; protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) Do they do the same thing? Is it any more efficient when processing the request to do it one way or another? Is there a technical term for what i am talking about? Thanks in advance for any explanation ...

How to Encrypt the "location" and "allow users" node in Web.config?
How can I encrypt this section/information in my "Web.config" file? I was able to encrypt my connection strings but it would not encrypt this section. Any help or suggestions would be greatly appreciated.  <location path="folder/subFolder">   <system.web>      <authorization>         <allow users="DomainName\User_A"/>         <allow users="DomainName\User_B"/>      &n...

web user control "delay problem"
Hello I'm trying to do the "master page" effect in .NET 1.1, and this is a technique I developed in my student times, some time ago. I've seen what you can do with master pages today in .net 2.0, and I've seen what you can do with Dot Net Nuke, and I'm impressed with both. But anyway, I'll try to explain my problem. What I've done, is to build a main page (default.aspx) I've build several web user controls in default.aspx in page_init event, I run my method RenderPage(), render page takes no parameters and examines the querystring to determine which web user control its suppose to rende...

Web User Control ... Where does the "Namespace" go ?
Hi All, I would like to add a web user control to a namespace in my project... But can't add the namespace in the normal place.... If I select add new web user control I get... ascx ... <%@ Control Language="VB" AutoEventWireup="false" CodeFile="MyWebUserControl.ascx.vb" Inherits="Controls_MyWebUserControl" %> Code behind... Partial Class Controls_MyWebUserControl Inherits System.Web.UI.UserControl End Class I can drag the control on to my web pages and end up with <%@ Register TagPrefix="MAPS" Namespace="MAPS"%> <%@ Register Src="../Controls/MyWebUserControl....

How can reference user controls (.ascx controls) using "Reference" directive in a multiple web project scanario?
Trying to reference .ascx controls from one web project into another web project.  I read the following tutorial from http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx Tutorial 6: Creating and Using User Control Libraries  In this sample it details how to reference .ascx control from another web project using "Register" directive. I wanted to reference using "Reference" directive which is currently throwing a exception. Here is the sample code that I have.  <%@ Reference Control="/ctl/MessageBox.ascx" %> &nbs...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

Web resources about - Javascript inside "web user control" not run if load "web user control" under ajax UpdatePanel - asp.net.ajax-ui

Resources last updated: 1/22/2016 12:17:13 AM