Private: MY Note


While Loop

Posted in JAVASCRIPT by dev1 on the January 25, 2008

var foundOne;
while (foundOne != 0){
foundOne = Math.round(14 * Math.random());
document.write (foundOne + ‘<br>’);
}

Open new window and center on screen

Posted in JAVASCRIPT by dev1 on the January 25, 2008

<html>
<head>
<title>New Window</title>
<script Language=”JavaScript”>
<!–
function newwindow(w,h,webaddress) {

var viewimageWin = window.open(webaddress,’New_Window’,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=Yes,resizable=no,copyhistory=no,width=’+w+’,height=’+h);

viewimageWin.moveTo(screen.availWidth/2-(w/2),screen.availHeight/2-(h/2));

}
//–>
</script>
</head>
<body>
<a href=”JavaScript:newwindow(500,300,’www.squeekmachine.co.uk’);”>Click here</a> to open new window.
</body>
</html>

Web develop tutorial

Posted in JAVASCRIPT, OTHER, dom by dev1 on the November 10, 2007

JavaScript Validation

Posted in JAVASCRIPT by dev1 on the October 22, 2007

function Validate()
        {          
           
var _vendor = document.getElementById(txtVendorCode);
           
var _receiver = document.getElementById(txtReceiver);
           
var _payment = document.getElementById(ddlPayment);
           
var _x = _payment.options[_payment.selectedIndex].value;           
                                   
           
var _str = “”;           
           
           
if (_vendor.value.length == 0)
            {
               
if (_str.length != 0) {_str += , ; }
                _str
+= Venfor code;                  
            }
           
           
if (_payment.selectedIndex == 0)
            {  
               
if (_str.length != 0) {_str += , ; }
                _str
+= Payment method;
            }
           
           
if (_receiver.value.length == 0)
            {
               
if (_str.length != 0) {_str += , ; }
                _str
+= ชื่อผู้รับเงิน;               
            }                       
           
           
if (_str.length != 0)
            {
                alert(
กรุณาระบุ + _str);
               
return false;           
            }
           
           
return;
           
        }

Rounded corner CSS+JS and more

Posted in CSS-xhtml, JAVASCRIPT, css by dev1 on the October 18, 2007

Vertical Text

Posted in JAVASCRIPT by dev1 on the October 17, 2007

Very simply, this guide shows how to make your text vertical using some simple CSS. If the examples below are not vertical then you are not using IE. This technique makes use of “Visual Filters” which are an IE only technology at present.

Tested in IE6 Icon

CSS Code

You can easily make vertical text with the following css:

In to the <head> section put your CSS:

<style>
<!–
.verticaltext {
writing-mode: tb-rl;
filter: flipv fliph;
}
–>
</style>

And into the body:

<div class=”verticaltext”>Test-1</div>

The result, if it works in your browser, should be:

  vertical1 (1K)

If we want to play with this a little we can, for example, change the filter from ‘flip vertical - flip hotizontal’ to ‘flip vertical - flip vertical’. Combining this with the first example we can have the following:

  vertical2 (1K)

It is also advised to specify the width otherwise you may get word wrap.

It’s not entirely useful but what the heck

ref: http://www.ssi-developer.net/css/vertical-text.shtml

Registering scripts in ASP.NET controls (the right way)

Posted in ASP.NET, JAVASCRIPT by dev1 on the October 17, 2007

Let’s start out with an innocent control that registers a simple script file include:

    public class BaseControl : Control {
protected override void OnPreRender(EventArgs e) {
Page.ClientScript.RegisterClientScriptInclude(
GetType(),
“InitScript”,
ResolveClientUrl(“~/ScriptLibrary/BaseControlInitScript.js”));
base.OnPreRender(e);
}
}

All the script file does is show a little alert message when it is loaded. Stick as many of these BaseControl controls as you want on a page and the script gets included only once. This happens because ASP.NET uses the first parameter (type) and second parameter (key) in the call to RegisterClientScriptInclude to determine the uniqueness of the script. Now a customer decides to write a custom control that derives from my control and for whatever reason decides to add no new functionality (not that it matters, but this customer is really lazy!):

    public class DerivedControl : BaseControl {     }

What happens if you add one BaseControl and one DerivedControl to the page? How many scripts get included? Well, let’s just say that I wouldn’t be writing this blog if the answer was only one.

Since the BaseControl used GetType() as its type parameter for RegisterClientScriptInclude, the return value of GetType() is unique for each type that derives from BaseControl. As we all know, typeof(BaseControl) != typeof(DerivedControl). Since the types are unique (and thus distinct), ASP.NET concludes that these are two distinct requests to register a script and it gets included twice in the rendered page.

The fix, fortunately, is very simple. Just replace GetType() with something constant, such as typeof(BaseControl). This way when the code executes in the context of DerivedControl, the constant Type value remains the same, and ASP.NET removes the duplicate registration request.

At this point you might wonder why ASP.NET detects duplicates based on type and key instead of based on URL. The answer: I have no idea why. A possible reason that it was done is that the same script URL might return different results each time. For example, maybe it’s a script for advertisements and the URL is http://www.example.org/ads/AutomaticAd.aspx and it returns different script for each request. If ASP.NET eliminated duplicates it might cause a site to not work properly. Another reason is that different URLs get canonicalized to the same value. Should ASP.NET consider “foo.js” and “FOO.js” the same? On Windows they’re the same, but on Unix they are not. Keep it simple.

The reality is that it doesn’t matter much anymore why it was done since that’s the way it is. The important part is that you have to be careful when you’re writing controls that register scripts. Go take a look at all your calls to ASP.NET’s Page.ClientScript and ASP.NET AJAX’s ScriptManager and see what types you’re passing in.

Unfunny story: In my numerous years reviewing other people’s sample ASP.NET controls you wouldn’t believe how many people decided it was a good idea to pass in typeof(int) for the type parameter and the string “key” for the key parameter. Now I wonder how many people used two different sample controls on the same page and realized that they don’t work together.

ref: http://weblogs.asp.net/leftslipper/default.aspx

Sys.WebForms.PageRequestManager.getInstance()

Posted in .NET, AJAX, JAVASCRIPT by dev1 on the September 27, 2007

http://www.asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerPageLoadedEvent.aspx
http://www.asp.net/learn/ajax-videos/video-172.aspx
http://www.asp.net/learn/ajax-videos/video-165.aspx
 

เอา JavaScript ไว้หลัง tag <asp:ScriptManager ID=”ScriptManager1″ />

<%@ Page Language=C# %><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
  “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”
><script runat=”server”>protected void ProcessClick_Handler(object sender, EventArgs e)
  {
  System.Threading.Thread.Sleep(
2000);
  }
</script><html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
 
<title>PageRequestManager beginRequest Example</title>
 
<style type=”text/css”>
  body
{
  font-family
: Tahoma;
 
}
  div.AlertStyle
 
{
  background-color
: #FFC080;
  top
: 95%;
  left
: 1%;
  height
: 20px;
  width
: 270px;
  position
: absolute;
  visibility
: hidden;
 
}
 
</style>
</head>
<body>
 
<form id=”form1″ runat=”server”>
 
<div>
 
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” /> <script type=”text/javascript” language=”javascript”>
  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
 
function BeginRequestHandler(sender, args)
  {
 
var elem = args.get_postBackElement();
  ActivateAlertDiv(
visible, AlertDiv, elem.value + processing…);
  }
 
function EndRequestHandler(sender, args)
  {
  ActivateAlertDiv(
hidden, AlertDiv, );
  }
 
function ActivateAlertDiv(visstring, elem, msg)
  {
 
var adiv = $get(elem);
  adiv.style.visibility
= visstring;
  adiv.innerHTML
= msg;
  }
 
</script><asp:UpdatePanel ID=”UpdatePanel1″ UpdateMode=”Conditional” runat=”Server”>
 
<ContentTemplate>
 
<asp:Panel ID=”Panel1″ runat=”server” GroupingText=”Update Panel”>
  Last update:
 
<%= DateTime.Now.ToString()%>.
 
<br />
 
<asp:Button runat=”server” ID=”Button1″ Text=”Process 1″ OnClick=”ProcessClick_Handler” />
 
<asp:Button runat=”server” ID=”Button2″ Text=”Process 2″ OnClick=”ProcessClick_Handler” />
 
</asp:Panel>
 
</ContentTemplate>
 
</asp:UpdatePanel>
 
<div id=”AlertDiv” class=”AlertStyle”>
 
</div>
 
</div>
 
</form>
</body>
</html>

ref: http://asp.net/ajax/documentation/live/Tutorials/CreateSimpleAJAXApplication.aspx

Handle error in client side

Posted in .NET, AJAX, JAVASCRIPT by dev1 on the September 27, 2007

<script type=”text/javascript”>
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(requestEndHandler );

// This function will handle the end request event
function requestEndHandler(sender, args) {
   if( args.get_error() ){
      document.getElementById(“errorMessageLabel”).innerText = 
         args.get_error().description;
      args.set_errorHandled(true);
   }
}
</script>

<div id=”errorMessageLabel”></div>

Debug javascript edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

Posted in JAVASCRIPT by dev1 on the September 27, 2007

Firebug integrates with Firefox to put a wealth of web development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

Just the way you like it

Firebug is always just a keystroke away, but it never gets in your way. You can open Firebug in a separate window, or as a bar at the bottom of your browser.

Next Page »