About liyenz

A bit about myself, I love to eat and take pictures of food and share it with everyone. I do some writing on my food hunting experience but I am not a blogger who write reviews for the restaurants or websites. Just have fun while viewing and reading my blog.

First Retouch into .Net Programming

Hi, it has been a while since my very last post under my Learning Bible title. Today, I spent my time to re-touch .Net programming. It has been two years not doing any web programming and I have this re-touch will bring me more new ideas. Ultimately, web programming is not my next main interest. It is just a warm-up session with a familiar platform.

Today I tried our the JQuery on setting a focus onto the textbox. Simple as a piece of cake for many programmers. I started with adding the below script into my master page,
<script type=”text/javascript” src=”/scripts/jquery-1.4.1.min.js”></script>. If you need guide, this website shows how to do it.
http://stackoverflow.com/questions/22664066/jquery-in-asp-net-web-form-with-a-master-page

I am sure there are newer versions of JQuery available. I found an article which is nicely explained which methods to be used to include jQuery into your project. http://www.codeproject.com/Tips/471799/jQuery-introduction-and-how-to-use-jQuery-with-ASP 

And, there is a demo available for setting focus on a textbox. http://jsfiddle.net/4fXLn/
This demo is based on onclick() function. If you’re doing page on load, then you can just remove the onclick() function.

<script type=”text/javascript” language=”javascript”>
$(document).ready(function() {
$(‘#MainContent_LoginUser_UserName’).focus();
});
</script>

Since I’m using master page, the id turned to be MainContent_LoginUser_UserName else you can just use the id from <input>.

And, you’re done!

[SQL] Test Connection

I feel this is a good and simple step to check the connection to a database. I would like to re-post here  and credit the writer.

How to Test a Database Connection String using NotePad
Create and Configure a Universal Data Link (.udl) File with Notepad.

I just came across a way to test a data providers connection string (like a SQL Server database) with the help of a plain text file using Notepad. To investigate and test out if your connection string works, your going to want to create a UDL file. To do this, follow these steps:

1) Open up Notepad and create an empty text file, then click File -> click Save -> and save it with the File name: TestConnection.udl to your desktop.
2) Go to your desktop and double-click on the TestConnection.udl file you just created and the Data Link Properties box will popup.
3) Select the Provider tab and Find the provider that you want to connect with and click Next >>.
4) Now from the Connection tab, select or enter your source/ server name -> then enter information to log on to server -> and select the database on the server.
5) Click Test Connection and click OK to save the file.

Note: If errors occur during testing of your connection string, you will get a popup box with the error message.

Once, you’ve successfully tested your connection string, now go and compare the details of your TestConnection.udl with your (website) project connection string to see if they are similiar.

 Source: http://www.gotknowhow.com/articles/test-a-database-connection-string-using-notepad
Credit to: Doug Kennard

Google Host jQuery

While searching for some jQuery tutorials, I come across to this website,
http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/

Doing so has several advantages over hosting jQuery on your server(s): decreased latency, increased parallelism, and better caching. It is quite interesting to know about the benefits of it.

Implementation method:
Google suggested method

<script type="text/javascript"
        src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  // You may specify partial version numbers, such as "1" or "1.3",
  //  with the same result. Doing so will automatically load the
  //  latest version matching that partial revision pattern
  //  (e.g. 1.3 would load 1.3.2 today and 1 would load 1.7.1).
  google.load("jquery", "1.7.1");

  google.setOnLoadCallback(function() {
    // Place init code here instead of $(document).ready()
  });
</script>

Normal method

<script type="text/javascript"
 src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    // This is more like it!
  });
</script>

If you’re curious why the script reference is missing the leading http:, that’s a helpful trick which allows you to use a single reference that works on both HTTP and HTTPS pages.

Besides Google, Microsoft also host the jQuery libraries. If want to call in this method,

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>


[?]html

I came across a webpage with extension, phtml. I do not know whether it is because I did not do programming for a while, things change so much or actually it is already there since long time ago. I am curious to know what phtml means.

In short, PHTML (or it’s sometimes called a PHP) page is a Web page that includes a script written in PHP.

[PHOTOGRAPHY] Night Photography

Key problems:
1) Keeping camera stable
2) Image noise

Tips:
1) A tripod or other support to keep it steady
2) Set larger aperture and turn off camera flash
3) Set your camera 10 second self-timer
4) Select your camera landscape mood which ensure current focus
5) Select camera night scene mood

Link:
http://stylepeterson.com/photography-articles/night-photography-tips
http://dptnt.com/2008/10/night-photography-ideas-and-techniques/
http://www.goodphotography.info/intermediate/night-photography-tips/

[VS2005] Textbox Auto Expand

Here is an example of auto expand a textbox.

1. Control declaration:

<asp:TextBox ID=”txtMsg” runat=”server”  TextMode=”MultiLine” style=”overflow:hidden” onkeyup=”AutoExpand(this, event)” Rows=”2″ />

2. JavaScript function:

function AutoExpand(txtBox, event)
{
if (event.keyCode == “13” || event.keyCode == “8”) {
var therows = 0
var thetext = document.getElementById(txtBox.id).value;
var newtext = thetext.split(“\n”);
therows += newtext.length

document.getElementById(txtBox.id).rows = therows;
return false;
}
}

[SQL] Generate Multiples Rows of Execution Query

I needed to run few hundreds rows of records and it is very troublesome when I have to change the ID for each time I execute a command. I was taught to write out the command in this way:-

select ‘DECLARE @i INT DECLARE @s VARCHAR(200) EXEC [dbo].[adm_sp_coin_adjust2]  ‘ +
””+PassportID+”’, ”liyen”, ”127.0.0.1”, @i output, @s output ‘ from dbo.MFlist

It grabs all the IDs from the table and the output from the above syntax will be the hundreds rows of records that are ready to be executed. It is really amazing.

[VS2005] HEX to RGB

Changing the Hex value of a color to RGB format can be done using the following example.

if (HexColor.Replace(“#”, “”).Length == 6)
{
byte r, g, b;
HexColor = HexColor.Replace(“#”, “”);

r = Convert.ToByte(HexColor.Substring(0, 2), 16);
g = Convert.ToByte(HexColor.Substring(2, 2), 16);
b = Convert.ToByte(HexColor.Substring(4, 2), 16);

series.Color = Color.FromArgb(r, g, b);
}
else
throw new Exception(“Invalid HEX value”);

[SQL] NEWID()

The following is the syntax of getting a unique ID using the NEWID() function. First, declare a variable to store the unique ID and then set the unique ID to the variable.

DECLARE @chvGUID VARCHAR(20)
SELECT @chvGUID =  (LEFT(NEWID(),(20)))

A common NEWID() function will return values for example like this, ‘A972C577-DFB0-064E-1189-0154C99310DAAC12’