<?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>Eclipsed4utoo&#039;s Blog&#187; alert</title>
	<atom:link href="http://eclipsed4utoo.com/blog/tag/alert/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsed4utoo.com/blog</link>
	<description>Not Your Ordinary Programmer</description>
	<lastBuildDate>Thu, 08 Sep 2011 17:09:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ASP.Net &#8211; Calling JavaScript from Code Behind</title>
		<link>http://eclipsed4utoo.com/blog/asp-net-calling-javascript-from-code-behind/</link>
		<comments>http://eclipsed4utoo.com/blog/asp-net-calling-javascript-from-code-behind/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 13:07:30 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=38</guid>
		<description><![CDATA[.Net gives us the ability to call javascript code from the code behind. This means that you don&#8217;t have to write the javascript code in the &#8220;Source&#8221; of the aspx page. Just for an example, let&#8217;s say that you have a button on a form that just want to popup an alert that says &#8220;HEY&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>.Net gives us the ability to call javascript code from the code behind. This means that you don&#8217;t have to write the javascript code in the &#8220;Source&#8221; of the aspx page.</p>
<p>Just for an example, let&#8217;s say that you have a button on a form that just want to popup an alert that says &#8220;HEY&#8221; when it is clicked.</p>
<pre class="brush: csharp;">
protected void btnHey_Click(object sender, EventArgs e)
{
     StringBuilder sb = new StringBuilder();
     sb.Append(&quot;&lt;script language='javascript'&gt;alert('HEY');&lt;/script&gt;&quot;);

     // if the script is not already registered
     if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), &quot;HeyPopup&quot;))
          ClientScript.RegisterClientScriptBlock(Page.GetType(), &quot;HeyPopup&quot;, sb.ToString());
}
</pre>
<p>To run a method that is already defined in the .aspx page, you would use similar code, but with one difference:</p>
<pre class="brush: csharp;">
// javascript method
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
    function ShowMessage(myMessage){
        alert(myMessage);
    }
&lt;/script&gt;

// C# code
protected void btnHey_Click(object sender, EventArgs e)
{
   StringBuilder sb = new StringBuilder();
   sb.Append(&quot;ShowMessage('hey');&quot;);

   // if the script is not already registered
   if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), &quot;HeyPopup&quot;))
       // notice that I added the boolean value as the last parameter
       ClientScript.RegisterClientScriptBlock(Page.GetType(), &quot;HeyPopup&quot;, sb.ToString(), true);
</pre>
<p>And it&#8217;s that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/asp-net-calling-javascript-from-code-behind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

