<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Calle Arnesten&#039;s Blog &#187; JavaScript</title>
	<atom:link href="http://www.arnesten.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arnesten.com</link>
	<description>Web Development, Test Driven Development, NHibernate, ASP.NET MVC, jQuery and more..</description>
	<lastBuildDate>Sun, 10 Jan 2010 18:35:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Trouble when including JavaScript block with Telerik Ajax Panel</title>
		<link>http://www.arnesten.com/2007/05/14/trouble-when-including-javascript-block-with-telerik-ajax-panel/</link>
		<comments>http://www.arnesten.com/2007/05/14/trouble-when-including-javascript-block-with-telerik-ajax-panel/#comments</comments>
		<pubDate>Mon, 14 May 2007 16:28:52 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/?p=10</guid>
		<description><![CDATA[Today I was having quite a bit of problem when I wanted to include javascript from a control inside a Telerik Ajax Panel. The javascript in question was dynamically generated and should only be added sometimes depending on what action was made inside the ajax panel. The first thing I tried is the standard way [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was having quite a bit of problem when I wanted to include javascript from a control inside a <a href="http://www.telerik.com/demos/aspnet/Ajax/Examples/Panel/FirstLook/DefaultCS.aspx">Telerik Ajax Panel</a>. The javascript in question was dynamically generated and should only be added sometimes depending on what action was made inside the ajax panel.</p>
<p>The first thing I tried is the standard way of registering javascript blocks, namely using <a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx">Page.ClientScript.RegisterClientScriptBlock</a>. That didn&#8217;t work, which when I thought about it was logical as the script is added high up in the html and not inside the ajax panel. </p>
<p>Secondly, I read a bit on Telerik&#8217;s support pages. It suggested that I used RadAjaxPanel.EnableOutsideScripts and RadAjaxPanel.ResponseScripts. I didn&#8217;t get this to work either directly, and got outofmemory exception in javascript. Due to time constraints I didn&#8217;t investigate this properly. I will try and write and update soon, if I remember.</p>
<p>The last thing I tried was to just include the javascript inside the html of the ajax panel. Like the following code suggested I did this by using a LiteralControl, containing the script, that is inserted in the ajax panel&#8217;s control collection.</p>
<pre class="csharpcode">
RadAjaxPanel panel = <span class="kwrd">new</span> RadAjaxPanel();

<span class="kwrd">if</span> (someCondition)
{
  <span class="kwrd">string</span> myScript = <span class="str">"function MyAlert() { alert('Hello world'); }"</span>;
  LiteralControl scriptControl = <span class="kwrd">new</span> LiteralControl();
  script.Text = <span class="kwrd">string</span>.Format(
    <span class="str">@"&lt;script type="</span><span class="str">"text/javascript"</span><span class="str">"&gt;{0}&lt;/script&gt;"</span>,
    myFunction);
  panel.Controls.Add(scriptControl);

  Button alertButton = <span class="kwrd">new</span> Button();
  alertButton.OnClientClick(<span class="str">"MyAlert(); return false;"</span>);
  panel.Controls.Add(alertButton);
}</pre>
<p>For the sake of simplicity the javascript that is dynamically added in this example is rather static. This turned out to work. I should mention that this trick will work just as well with the standard Microsoft ASP.NET Ajax Update Panel. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2007/05/14/trouble-when-including-javascript-block-with-telerik-ajax-panel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

