2011-04-24

.NET: Executing Javascript From Codebehind




Calling a JavaScript function from codebehind is quiet simple, yet it confuses a lot of developers. Here's how to do it. Declare a JavaScript function in your code as shown below:

JavaScript

<head runat="server">
<
title>Call JavaScript From CodeBehindtitle>
<
script type="text/javascript">
function
alertMe() {
alert('Hello');
}
script>
head>

In order to call it from code behind, use the following code in your Page_Load

C#

protected void Page_Load(object sender, EventArgs e)
{
if (!ClientScript.IsStartupScriptRegistered("alert"))
{
Page.ClientScript.RegisterStartupScript(this.GetType(),
"alert", "alertMe();", true);
}
}

VB.NET

If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
Page.ClientScript.RegisterStartupScript _
(Me.GetType(), "alert", "alertMe();", True)
End If

The Page.ClientScript.RegisterStartupScript() allows you to emit client-side script blocks from code behind. More info here http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx

To call the JavaScript code on a button click, you can add the following code in the Page_Load

btnCall.Attributes.Add("onclick", " return alertMe();");

2010-04-05

Speed Up Ubuntu's Startup

Speed up Ubuntu (10.4) boot time. It uses a method called profiling. This is how you do it:

  1. @ boot screen press “e” (for edit).
  2. Select “kernel”
  3. Press “e” again.
  4. Add “profile” (no quotes) at the end line +
  5. Press “b” (for boot).
Now the profiling will begin. It profiles your boot process, figuring out what files are accessed at boot time. Then it sorts them according to how the are stored in drive.

2007-03-27

Collatz Conjecture

Im currently working on a ruby programming that will output the iterative cycles for the collatz function.



2005-05-05

...thinking primal...

haven't been here in a while. But that is obvious. So wont dwell on it. Enough.

...Couldn't sleep, my brain is always most active at night. but today it wasn't just simply my biological clock coming on once it was sunset.

i have been thinking primes - more like seeing primes. im finally understanding and visualizing so many things in number theory. especially those things that have to do with primes. i have been reading this book The Music of the Primes: Searching to Solve the Greatest Mystery in Mathematics.

the reason i got out of bed to write is that i finally want to finish up writing a java class: R2Plane (extends JPanel). And if possible to extend that class to R2Grid. One will be enough for tonight though. This is i hope to finish so i can get started analyzing some of my ideas that i have about the primes.

2005-02-21

...begin...ignition....

it is raining.
los angeles is seeing lotsa water.
the earth is drinking.

checked out some books on c# and java.
avoided the heavy buddhist stuff: nagarjuna, mipham's.
was tempted by stephen batchelor's Verses from the Center.

left lights on in the car, due to rain.
battery died, had to come home and ask mi apa for help.
got all that fixed.

sindy, my baby, was very tired.
poor thing, havent let her sleep well. >:)
shes happy with her new gba, and her pokemon game.
she named one of her mons: speedie.
she really likes her little snail.