Javascript validation for input limited text into textbox or textarea
On design page source::
----------------------------
On b/h code source page:
protected void Page_Load(object sender, EventArgs e)
{
txtLocation.Attributes.Add("onkeypress", "return LocationLength()");
txtLocation.Attributes.Add("onkeyup", "return LocationLength()");
}
Happy Coding..!!
Thursday, October 23, 2008
Saturday, October 18, 2008
Get And Set The System Date And Time using c#
Have you want to get your current system date and time as well as set the system date and time using c# code.
here it is, C# code snippet that uses unmanaged code to retrieve the current date and time of the Windows operating system, and also sets it to the specified values.
here it is, C# code snippet that uses unmanaged code to retrieve the current date and time of the Windows operating system, and also sets it to the specified values.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace Sample
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public struct SystemTime
- {
- public ushort Year;
- public ushort Month;
- public ushort DayOfWeek;
- public ushort Day;
- public ushort Hour;
- public ushort Minute;
- public ushort Second;
- public ushort Millisecond;
- };
- [DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
- public extern static void Win32GetSystemTime(ref SystemTime sysTime);
- [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
- public extern static bool Win32SetSystemTime(ref SystemTime sysTime);
- private void button1_Click(object sender, EventArgs e)
- {
- // Set system date and time
- updatedTime.Year = (ushort)2008;
- updatedTime.Month = (ushort)4;
- updatedTime.Day = (ushort)23;
- // UTC time; it will be modified according to the regional settings of the target computer so the actual hour might differ
- updatedTime.Hour = (ushort)10;
- updatedTime.Minute = (ushort)0;
- updatedTime.Second = (ushort)0;
- // Call the unmanaged function that sets the new date and time instantly
- Win32SetSystemTime(ref updatedTime);
- // Retrieve the current system date and time
- Win32GetSystemTime(ref currTime);
- // You can now use the struct to retrieve the date and time
- MessageBox.Show("It's " + currTime.Hour + " o'clock. Do you know where your C# code is?");
- }
- }
- }
Delete All Temporary Internet Files Of Internet Explorer
- using System.IO;
- public static void Main()
- {
- ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))); // Execute ClearFolder() on the IE's cache folder
- }
- void ClearFolder(DirectoryInfo diPath)
- {
- foreach (FileInfo fiCurrFile in diPath.GetFiles())
- {
- fiCurrFile.Delete();
- }
- foreach (DirectoryInfo diSubFolder in diPath.GetDirectories())
- {
- ClearFolder(diSubFolder); // Call recursively for all subfolders
- }
- }
Thursday, October 16, 2008
How to get IP address of the Current Machine?
public void UseDNS()
{
string hostName = Dns.GetHostName();
Console.WriteLine("Host Name = " + hostName);
IPHostEntry local = Dns.GetHostByName(hostName);
foreach(IPAddress ipaddress in local.AddressList)
{
Console.WriteLine("IPAddress = " + ipaddress.ToString());
}
}
{
string hostName = Dns.GetHostName();
Console.WriteLine("Host Name = " + hostName);
IPHostEntry local = Dns.GetHostByName(hostName);
foreach(IPAddress ipaddress in local.AddressList)
{
Console.WriteLine("IPAddress = " + ipaddress.ToString());
}
}
Saturday, October 11, 2008
Resolving w3c validation issues details...
For those who are wondering why should one bother with W3C Validations,
please read Why should we Validate our WebSites?
When validating your website using W3C some weird errors might occur
An Example is
even if you haven't given the border attribute
The Reason
The Solution(Step Wise)
1.Right Click on your Solution Explorer
2.Click on Add ASP.NET Folder ---> App_Browsers
3.Now Click on App_Browsers ---> Add New Item
4.A dialog Box now pops up with some Visual Studio Installed Templates.
Select the Browser File Template from there, change the name as W3CValidations.browser(any other convenient name also) and Click on the Add Button
5.Delete the whole XML MarkUp code inside the W3CValidations.browser
6.Place the following code instead
7.Now upload this Folder nad File to your Hosting Service
8.Re Validate using W3C Validator
9.Bingo! You got a Clean Validation Certificate.
10. Show off the Validation Certificate to all those who cares [:)]
Happy coding..!!
ref:
http://fun2code.blogspot.com/search?updated-max=2008-08-28T15%3A02%3A00%2B05%3A30&max-results=3
please read Why should we Validate our WebSites?
When validating your website using W3C some weird errors might occur
An Example is
there is no attribute "border".
even if you haven't given the border attribute
The Reason
The ASP.NET engines sees the W3C validator as down-level browser and renders
non-XHTML compliant code. Your code is most likely fine. The problem is with
ASP.NET.
The Solution(Step Wise)
1.Right Click on your Solution Explorer
2.Click on Add ASP.NET Folder ---> App_Browsers
3.Now Click on App_Browsers ---> Add New Item
4.A dialog Box now pops up with some Visual Studio Installed Templates.
Select the Browser File Template from there, change the name as W3CValidations.browser(any other convenient name also) and Click on the Add Button
5.Delete the whole XML MarkUp code inside the W3CValidations.browser
6.Place the following code instead
7.Now upload this Folder nad File to your Hosting Service
8.Re Validate using W3C Validator
9.Bingo! You got a Clean Validation Certificate.
10. Show off the Validation Certificate to all those who cares [:)]
Happy coding..!!
ref:
http://fun2code.blogspot.com/search?updated-max=2008-08-28T15%3A02%3A00%2B05%3A30&max-results=3
Saturday, October 4, 2008
use Messagebox in asp.net
Declaration:
using System.Windows.Forms;
Code:
MessageBox.Show("message right here!!");
using System.Windows.Forms;
Code:
MessageBox.Show("message right here!!");
Msgbox for ASP.Net
Messsagebox function for ASP.Net.
Call this function from the server side, and a msgbox will appear on the client browser. As a bonus, the msgbox javascript is added after the rest of the form, so the browser displays the html for the page and then the msgbox.
Declaration:
Imports System.Text
Code:
Public Sub UserMsgBox(ByVal sMsg As String)
Dim sb As New StringBuilder()
Dim oFormObject As System.Web.UI.Control
sMsg = sMsg.Replace("'", "\'")
sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))
sMsg = sMsg.Replace(vbCrLf, "\n")
sMsg = ""
sb = New StringBuilder()
sb.Append(sMsg)
For Each oFormObject In Me.Controls
If TypeOf oFormObject Is HtmlForm Then
Exit For
End If
Next
' Add the javascript after the form object so that the
' message doesn't appear on a blank screen.
oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))
end sub
Happy coding..!!
Call this function from the server side, and a msgbox will appear on the client browser. As a bonus, the msgbox javascript is added after the rest of the form, so the browser displays the html for the page and then the msgbox.
Declaration:
Imports System.Text
Code:
Public Sub UserMsgBox(ByVal sMsg As String)
Dim sb As New StringBuilder()
Dim oFormObject As System.Web.UI.Control
sMsg = sMsg.Replace("'", "\'")
sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))
sMsg = sMsg.Replace(vbCrLf, "\n")
sMsg = ""
sb = New StringBuilder()
sb.Append(sMsg)
For Each oFormObject In Me.Controls
If TypeOf oFormObject Is HtmlForm Then
Exit For
End If
Next
' Add the javascript after the form object so that the
' message doesn't appear on a blank screen.
oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))
end sub
Happy coding..!!
Subscribe to:
Posts (Atom)