Cacing Cau — Dunia Baru

October 3, 2006

Adding JScript Event To Aspx control

Filed under: C#

Hey Guys ini hal menarik yang aku dapat kemarin ketika ngedevelop web App C#,

Bagaimana cara menambahkan "Jscript event to Aspx control" , Here’s the tip ..

First ..

Tambahkan baris kode berikut .. 

<server code>

     TextBox1.Attributes.Add("onblur", "validateText(id);");

</server code> 

Kamu bisa menambahkan pada pageload atau event button component aspx

Secondly ..

Tambahkan beberapa baris kode pada .aspx kamu..

<client code>

    function validateText(Item)
    {
          chek=document.getElementById(Item).value;
                    if (chek=="cacau")
                    {
                        alert(" It’s Work ! ");
                    }
     } 

</client code> 

Dan coba run dan buktikan … emoticon

– code diatas menghasilkan

<view Html Source> 

    <asp:TextBox ID="TextBox1" runat="server" Enabled="true" Visible="True" onblur="validateText(ID)">

    </asp:TextBox>

</view Html Source>

– Hal yang menarik , apabila kita langsung menggunakan tag seperti pada <view html source> maka kemungkinan akan di tolak dan dianggap tidak valid oleh compiler.. (That what’s happen to me , it’s just me or ??) , Selamat Mencoba emoticon 

Comments »

The URI to TrackBack this entry is: http://cacau.blogsome.com/2006/10/03/adding-jscript-event-to-aspx-control/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Ian Main