Wednesday, June 11, 2008

Validation Control (One Numeric,alphapet,special char)

^.*(?=.{8,})(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+-=]).*$

Monday, May 26, 2008

File Upload Validator

<>
< Text="Upload File" />>
<><>
< id="RegularExpressionValidator1" runat="server"
ErrorMessage="Only mp3, m3u or mpeg files are allowed!"
ValidationExpression="^(([a-zA-Z]:)(\\{2}\w+)\$?)(\\(\w[\w].*))
+(.mp3.MP3.mpeg.MPEG.m3u.M3U)$"
ControlToValidate="FileUpload1">><>
< id="RequiredFieldValidator1" runat="server"
ErrorMessage="This is a required field!"
ControlToValidate="FileUpload1">><>

























Thursday, May 22, 2008

To Close Window

To Close Window
function CloseWindow()
{
bName = navigator.appName; //1
bVer = parseInt(navigator.appVersion); //2
if (typeof document.body.style.maxHeight != "undefined")
{
window.open('','_self');
window.close();
}
else
{
win = top;
win.opener = top;
win.close ();}
}

Tuesday, May 20, 2008

Page.RegisterStartupScript

uncomment it

//Page.RegisterStartupScript("myscritp", "
");

// Page.RegisterStartupScript("scritp", "
");

Monday, May 19, 2008

Sql Quries

ROW_NUMBER()
Select ROW_NUMBER()OVER( order by loginDate desc) As SrNo, UserLoginName, Firstname, Lastname, Email,Regdate, dbo.fnYesNo(isActive)UserActive, dbo.fnyesno(isDelete) UserDeleted,Count(isActive) as NoofLogins, Min(loginDate) FirstLoginTime, Max(loginDate)LastLoginTime from View_userLogging where customerId=1 group by UserLoginName, Firstname, Lastname, email, Regdate, isActive,CustomerID, isDelete,loginDate
Function Creation
CREATE FUNCTION [dbo].[fnAccessType] (@PassChar varchar(1))
RETURNS VARCHAR(30) as
BEGIN
Declare @Result varchar(30)
set @Result= Case @PassChar
When '0' then 'Public'
When '1' then 'Private'
When '2' then 'Protected'
End
RETURN (@Result)
END
Function Creation
Alter FUNCTION GetUserName (@UserLoginName varchar(100))
RETURNS VARCHAR(300) asBEGIN
Declare @Result varchar(300)
set @Result=(select FirstName +' '+ LastName+ ' ('+ UserLoginName+')' from UserLogin where UserLoginName=@UserLoginName)
RETURN (@Result)
End

Creating Function

ALTER FUNCTION [dbo].[fnUsage] (@UsgSec int)

RETURNS VARCHAR(10)

as

BEGIN
Declare @Result varchar(10),@min decimal,@mins int,@hrs int,@tmp varchar(10)
If (IsNumeric(@UsgSec)=1) Begin set @min=floor(@UsgSec/60)
If (@min>0 )

begin

set @hrs=@UsgSec/3600

set @mins=@min - floor(@min/60)*60
set @tmp=CAST(@hrs AS varchar(10)) + ':' +right(100+CAST(@mins as varchar(10)),2)
end

else

begin

set @tmp='0:00' end
set @Result = @tmp + ':' + right( 100+ Cast(convert(int,(@UsgSec % 60))as varchar (10)),2) EndElse Begin set @Result='0:00:00'

End
RETURN (@Result)
END

Friday, May 16, 2008

Database connection

Method1
{
cn.Open();
string ster="select *from Employee";
cmd.CommandText=Str;
cmd.Connection=cn;
dr=cmd.ExecuteReader()
if(!dr.Read())
{
string TempVar=(string) dr.GetValule(0);
drpEmployee.Items.Add(TempVar);
}
}
Method2
To fill DataGrid
{
cn.Open();
ds.Clear(0
string str="select *from Employee";
cmd.CommandTex=str;
cmd.Connection=cn;
da.SelectCommand=cmd;
da.Fill(ds,"Test");
gridEmployee.DataSource=ds;
gridEmployee.DataMember="Test";
gridEmployee.DataBind();
}
Method3
using System.Data.SqlClient;
Using System.Configuration;

Public Sql Connection cn=new SqlConnection(ConfigurationSetting.AppSettings.Get("ConnectionString")
public SqlCommand cmd=new SqlCommand();
public SqlDataAdaptor da=new SqlDataAdaptor();
Button Click
{
cn.Open();
cmd=new SqlCommand("School_Add",cn);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter parStudentName=new SqlParameter("@StudentName",SqlDbType.Varchar,50);
parStudentName.Value=this.txtStudentName.Text;
cmd.Parameters.Add(parStudentName);
"
"
cmd.ExecuteNonQuery();

}




Link Button in GridView

Button Click
{
GridViewRow row=(GridViewRow)((LinkButton)Sender).NamingContainer;
string ComplaintId=GridView1.DataKeys[row.RowIndex].Value.ToString();
string str=GridView1.Rows[row.RowIndex].Cells[3].Text.ToString();
}

File Uploading and Downloading

Uploading
string Location=Directory.GetDirectories(Server.MapPath("Directories"),EmpName)
//Loacation="D:Integerated\\Directories\\benil\"
string filename=Path.GetFileName(uplTheFile.Value);
if(finename=="")
{
return;
}
if(uplTheFile.PostedFile !=null)
{
uplTheFile.PostedFile.SaveAs(Location+ "" + filename);
//string finelname=path.GetFileName(FileUpload1.PostedFile.FileName);
}
*************
Download
public FileInfo file
file=new FileInfo(Server.MapPath("LeaveForm.doc")
if(file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition","attachment;filename=" +file.Name);
Response.ContentType="application/Octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}

Alert Message and Confirmation Message

<script type="text/javascript" language="javascript" >
function ShowMessage(msg)
{
alert(msg);
return false;
}
</script >

Inside PageLoad
btnSubmit.Attributes.Add("onclick","return ShowMessage (\"Hellow how r u?\");");

*****************
function conifrm()
{
if (confirm==true)
else
return false;
}

PageLoad
btnSave.Attributes.Add("onclick,"return confirm('Are You Sure');");
}
***************

Table Scrolling(x and y direction)

<div style="overflow-x:scroll;overflow-y:scroll;width:500 px;height:200 px" </div>

Java Script Window.Open Function

window.open("Product.aspx","News","location=no,scrollbars=yes,toolbar=no,directories=now,status=n0,resizable=no,
copyhistory=no,menubar=no,width=200,height=200,top=200,left=200")