17
Nov

This simple program will guide how to do client side validation of Form in JavaScript.

In this just make a form as follows:

  1. Name : <asp:TextBox ID=”txtName” />
  2. Email : <asp:TextBox ID=”txtEmail” />
  3. Web URL : <asp:TextBox ID=”txtWebUrl” />
  4. Zip : <asp:TextBox ID=”txtZip” />
  5. <asp:Button ID=”btnSubmit” OnClientClick=” return validate()” runat=”server” Text=”Submit” />

Now on the source code of this form in script tag write the following code:

<script language=”javascript” type=”text/javascript”>
function
validate()
{
if (document.getElementById(“<%=txtName.ClientID%>”).value==“”
)
{
alert(“Name Feild can not be blank”
);
document.getElementById(
“<%=txtName.ClientID%>”
).focus();
return false
;
}
if(document.getElementById(“<%=txtEmail.ClientID %>”).value==“”
)
{
alert(
“Email id can not be blank”
);
document.getElementById(“<%=txtEmail.ClientID %>”
).focus();
return false
;
}
var
emailPat = /^(\”.*\”|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid=document.getElementById(“<%=txtEmail.ClientID %>”
).value;
var
matchArray = emailid.match(emailPat);
if (matchArray == null
)
{
alert(
“Your email address seems incorrect. Please try again.”
);
document.getElementById(
“<%=txtEmail.ClientID %>”
).focus();
return false
;
}
if(document.getElementById(“<%=txtWebURL.ClientID %>”).value==“”
)
{
alert(
“Web URL can not be blank”
);
document.getElementById(
“<%=txtWebURL.ClientID %>”).value=
“http://”
document.getElementById(“<%=txtWebURL.ClientID %>”
).focus();
return false
;
}
var Url=
“^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$”
var tempURL=document.getElementById(“<%=txtWebURL.ClientID%>”
).value;
var
matchURL=tempURL.match(Url);
if(matchURL==null
)
{
alert(
“Web URL does not look valid”
);
document.getElementById(
“<%=txtWebURL.ClientID %>”
).focus();
return false
;
}
if (document.getElementById(“<%=txtZIP.ClientID%>”).value==“”
)
{
alert(
“Zip Code is not valid”
);
document.getElementById(
“<%=txtZIP.ClientID%>”
).focus();
return false
;
}
var digits=“0123456789″
;
var
temp;
for (var i=0;i<document.getElementById(“<%=txtZIP.ClientID %>”
).value.length;i++)
{
temp=document.getElementById(
“<%=txtZIP.ClientID%>”
).value.substring(i,i+1);
if
(digits.indexOf(temp)==-1)
{
alert(
“Please enter correct zip code”
);
document.getElementById(
“<%=txtZIP.ClientID%>”
).focus();
return false
;
}
}
return true
;
}
</script>

And in code behind file just write the below code.

In C#,

protected void Page_Load(object sender, System.EventArgs e)
{

btnSubmit.Attributes.Add(“onclick”, “return validate()”);

}

In VB,

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnSubmit.Attributes.Add(
“onclick”, “return validate()”
)
End Sub

Reference : http://source.witssquare.com

VN:F [1.7.4_987]
Rating: 5.0/5 (1 vote cast)
VN:F [1.7.4_987]
Rating: +1 (from 1 vote)

13
Nov

WCF,WPF and WWF in .Net

Author: admin

What Is Windows Communication Foundation?

The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example, the functions that Web services now provide include security, distributed transaction coordination, and reliable communication. The benefits of the changes in Web services should be reflected in the tools and technologies that developers use. Windows Communication Foundation (WCF)…

Read more…

Reference : http://source.witssquare.com/

VN:F [1.7.4_987]
Rating: 3.0/5 (2 votes cast)
VN:F [1.7.4_987]
Rating: +2 (from 2 votes)

13
Nov

The code sample defines a function GetExcelSheetNames that takes an Excel file’s path as input, opens it, and find out the sheet names in that file.

The function uses a OleDbConnection to connect to the data source (the excel file). The file is is referred by a DataTable and each row in this DataTable is a sheet in Excel file. And thus, the row names are obtained easily.

using System.IO;
using System.Data.OleDb;

protected void Page_Load(object sender, EventArgs e)
{
    GetExcelSheetNames(@"E:\\Book1.xls");
}

public string[] GetExcelSheetNames(string excelFileName)
 {
      OleDbConnection con = null;
      DataTable dt = null;
      String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
      "Data Source=" + excelFileName + ";Extended Properties=Excel 8.0;";
      con= new OleDbConnection(conStr);
      con.Open();
      dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

      if (dt == null)
      {
          return null;
      }

      String[] excelSheetNames = new String[dt.Rows.Count];
      int i = 0;

      foreach (DataRow row in dt.Rows)
      {
          excelSheetNames[i] = row["TABLE_NAME"].ToString();
          i++;
      }
      return excelSheetNames;
 }

Reference : http://source.witssquare.com/
VN:F [1.7.4_987]
Rating: 5.0/5 (1 vote cast)
VN:F [1.7.4_987]
Rating: +1 (from 1 vote)