protected void Page_Load(object sender, EventArgs e)
{
Button1_Click(Button1,new EventArgs());
}
void Button1_Click(object sender, EventArgs e)
{
//your code
}
Sunday, December 20, 2009
Friday, November 20, 2009
RegEx for allowing numeric value
Expression ^\d{0,2}(\.\d{1,2})?$
Description This regular expression validates that the data entered is a number with a maximum of two integers and two decimals and a minimum of one integer or one decimal.
Matches 99.99 | 99 | .99
Non-Matches 999.999 | 999 | .999
Description This regular expression validates that the data entered is a number with a maximum of two integers and two decimals and a minimum of one integer or one decimal.
Matches 99.99 | 99 | .99
Non-Matches 999.999 | 999 | .999
Labels:
Javascript
Wednesday, October 28, 2009
RegEx for Time in HH:MM AM/PM
if(txtTime.value.match("^(([0]?[1-9])|([1][0-2])):(([0-5][0-9])|([1-9])) [AP][M]$"))
{
alert("valid date");
}
{
alert("valid date");
}
Labels:
Javascript
Tuesday, October 27, 2009
Convert Date to DD/MM/YYYY format in VB.net
Dim enGB As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-GB")
Dim dtDate as datetime
dtDate=Convert.ToDateTime(dpadmitdate.text, enGB)
---------------------------------------------------------------------------------------
To show date time from database in a different format(AM and PM
lbldate.Text = Convert.ToDateTime(dsResult.Tables(0).Rows(0)("CreatedDate").ToString()).ToString("dd-MMM yyyy hh:mm tt")
Dim dtDate as datetime
dtDate=Convert.ToDateTime(dpadmitdate.text, enGB)
---------------------------------------------------------------------------------------
To show date time from database in a different format(AM and PM
lbldate.Text = Convert.ToDateTime(dsResult.Tables(0).Rows(0)("CreatedDate").ToString()).ToString("dd-MMM yyyy hh:mm tt")
SQL DateName,DatePart
To get the Day of the given Date
---------------------------------
SELECT DATEPART(dw,GETDATE())
SELECT DATENAME(dw,GETDATE())
---------------------------------
SELECT DATEPART(dw,GETDATE())
SELECT DATENAME(dw,GETDATE())
Monday, October 19, 2009
Regex for US phone number
if(txtbox.value.match("^(\\+?1[- ]?)?\\(?(\\d{3})\\)?[\\s-]?(\\d{3})[\\s-]?(\\d{4})$"))
{
alert('true');
}
{
alert('true');
}
Monday, October 5, 2009
Visual Studio short cut
http://www.mobydisk.com/softdev/techinfo/dotnetkeyboard.htmlVisualStudio_ShortCuts
@@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT
SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function
SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
Example query to understand
--/********create a table*************/
create table TB_01(id int identity(1,1),name varchar(50))
--/********create another table*************/
create table TB_02(id int identity(1,1),name varchar(50))
--/***create a Procedure to insert value into table1 and printing the last inserted identity value******/
create procedure sp_01
(@nam varchar(50))
as
begin
declare @ident varchar(50);
insert into TB_01([name]) values(@nam)
select @ident=@@identity;
print @ident
end
--/********create a trigger to insert in table 2 while inserting in table 1*************/
create trigger trg01 on TB_01
after insert
as
begin
insert into TB_02([name]) select [name] from inserted
end
select * from TB_01
exec sp_01 'jayaraman'
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function
SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
Example query to understand
--/********create a table*************/
create table TB_01(id int identity(1,1),name varchar(50))
--/********create another table*************/
create table TB_02(id int identity(1,1),name varchar(50))
--/***create a Procedure to insert value into table1 and printing the last inserted identity value******/
create procedure sp_01
(@nam varchar(50))
as
begin
declare @ident varchar(50);
insert into TB_01([name]) values(@nam)
select @ident=@@identity;
print @ident
end
--/********create a trigger to insert in table 2 while inserting in table 1*************/
create trigger trg01 on TB_01
after insert
as
begin
insert into TB_02([name]) select [name] from inserted
end
select * from TB_01
exec sp_01 'jayaraman'
How to handle Click event in dynamically generated linkbutton
protected void Page_Load(object sender, EventArgs e)
{
LinkButton lnkbtn = new LinkButton();
lnkbtn.Text = "Link";
lnkbtn.Click += new System.EventHandler(this.LinkButton_Click);
lnkbtn.Visible = true;
ph01.Controls.Add(lnkbtn);
}
protected void LinkButton_Click(object sender, EventArgs e)
{
Response.Write("Jayaraman");
}
{
LinkButton lnkbtn = new LinkButton();
lnkbtn.Text = "Link";
lnkbtn.Click += new System.EventHandler(this.LinkButton_Click);
lnkbtn.Visible = true;
ph01.Controls.Add(lnkbtn);
}
protected void LinkButton_Click(object sender, EventArgs e)
{
Response.Write("Jayaraman");
}
Wednesday, September 30, 2009
To Dynamically Load a user control in aspx page
To dynamically load a user control in aspx page and call a public function in user control through the aspx page.
Control Guest_Comments = Page.LoadControl(Page.ResolveUrl("~/ResponseChunk.ascx"));
PHIndex.Controls.Add(Guest_Comments);
((ResponseChunk)Guest_Comments).GetRatingResponse(Convert.ToInt32(_PropertyID));
Control Guest_Comments = Page.LoadControl(Page.ResolveUrl("~/ResponseChunk.ascx"));
PHIndex.Controls.Add(Guest_Comments);
((ResponseChunk)Guest_Comments).GetRatingResponse(Convert.ToInt32(_PropertyID));
Friday, September 25, 2009
Trigger to insert in another table
ALTER TRIGGER onInsert ON Employee
FOR INSERT
AS
DECLARE @Age INT
DECLARE @message VARCHAR(50)
SET @Age=(SELECT age FROM inserted)
IF(@Age>20 and @Age<50)
BEGIN
INSERT INTO Employee1([Name],Age)
SELECT [Name],Age FROM inserted i
END
ELSE
BEGIN
SELECT @message 'message'
END
FOR INSERT
AS
DECLARE @Age INT
DECLARE @message VARCHAR(50)
SET @Age=(SELECT age FROM inserted)
IF(@Age>20 and @Age<50)
BEGIN
INSERT INTO Employee1([Name],Age)
SELECT [Name],Age FROM inserted i
END
ELSE
BEGIN
SELECT @message 'message'
END
Creating a Microsoft installer Package(MSI)
Creating a Microsoft installer Package(MSI)
Use Visual Studio 2005 to create a base Windows Installer package
To create a base Windows Installer package, follow these steps:
1. Start Visual Studio 2005.
2. On the File menu, click New, and then click Project.
3. In the New Project dialog box, expand Other Project Types under Project Types, click Setup and Deployment, and then click Setup Project under Visual Studio installed templates.
4. In the Name box, type Caspol.msi.
5. In the Location box, type the location of the Caspol.msi file, and then click OK.
6.A page with 2 panes open.
in the left pane under "filesystem on target machine" select application folder and remove rest other folder
7. in the solution explorer right click the newly created setup project and click Add--->ProjectOutput.add project output group box opens
8. choose primary output and contenet files from add project output group box and then ok.
9.select the setup project from solution explorer and and press f4..to view and edit the property
10.right click on root solution in solution explorer and go to properties,a solution property pages window opens.in the window, uncheck the "build" checkbox for the setup project.and then build the solution..
Here are some detailed instuctions on how to setup your web deployment project. There is a plugin below you may or may not need.
VS2005 / VS2008
http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx
http://www.dotnetheaven.com/Uploadfile/vijendrapal/DeployingASPNETAppls10292005000351AM/DeployingASPNETAppls.aspx?ArticleID=d7f3111a-d8d3-49ff-8ae6-04a24a2eae3a
http://msdn.microsoft.com/en-us/library/ms242499(VS.80).aspx
Use Visual Studio 2005 to create a base Windows Installer package
To create a base Windows Installer package, follow these steps:
1. Start Visual Studio 2005.
2. On the File menu, click New, and then click Project.
3. In the New Project dialog box, expand Other Project Types under Project Types, click Setup and Deployment, and then click Setup Project under Visual Studio installed templates.
4. In the Name box, type Caspol.msi.
5. In the Location box, type the location of the Caspol.msi file, and then click OK.
6.A page with 2 panes open.
in the left pane under "filesystem on target machine" select application folder and remove rest other folder
7. in the solution explorer right click the newly created setup project and click Add--->ProjectOutput.add project output group box opens
8. choose primary output and contenet files from add project output group box and then ok.
9.select the setup project from solution explorer and and press f4..to view and edit the property
10.right click on root solution in solution explorer and go to properties,a solution property pages window opens.in the window, uncheck the "build" checkbox for the setup project.and then build the solution..
Here are some detailed instuctions on how to setup your web deployment project. There is a plugin below you may or may not need.
VS2005 / VS2008
http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx
http://www.dotnetheaven.com/Uploadfile/vijendrapal/DeployingASPNETAppls10292005000351AM/DeployingASPNETAppls.aspx?ArticleID=d7f3111a-d8d3-49ff-8ae6-04a24a2eae3a
http://msdn.microsoft.com/en-us/library/ms242499(VS.80).aspx
Thursday, September 17, 2009
TARGET = "_blank"
TARGET = "_blank"
"_blank" opens the link in a new window.
Sample Code
===========
<html>
<head>
<title>
page</title>
</head>
<body>
<a href="http://www.google.co.in/" target="_blank">Google</a>
</body>
</html>
"_blank" opens the link in a new window.
Sample Code
===========
<html>
<head>
<title>
page</title>
</head>
<body>
<a href="http://www.google.co.in/" target="_blank">Google</a>
</body>
</html>
Wednesday, September 16, 2009
Sql-CEILING and Floor
CEILING
Returns the smallest integer that is greater than, or equal to, the given numeric expression.
for instance,
SELECT ceiling(1.5) will return "2"
--------------------------------------------------------------------------------
FLOOR
Returns the largest integer less than or equal to the given numeric expression
for instance SELECT floor(1.5)
will return "1"
Returns the smallest integer that is greater than, or equal to, the given numeric expression.
for instance,
SELECT ceiling(1.5) will return "2"
--------------------------------------------------------------------------------
FLOOR
Returns the largest integer less than or equal to the given numeric expression
for instance SELECT floor(1.5)
will return "1"
Tuesday, September 15, 2009
Query To get all the tables in Database
SELECT *
FROM sys.objects
WHERE type = 'u'
-------------------------------
Where 'u' stands for USER_TABLE
Where 'P' stands for SQL_STORED_PROCEDURE
Where 'TR' stands for SQL_TRIGGER
-------------------------------
FROM sys.objects
WHERE type = 'u'
-------------------------------
Where 'u' stands for USER_TABLE
Where 'P' stands for SQL_STORED_PROCEDURE
Where 'TR' stands for SQL_TRIGGER
-------------------------------
Labels:
Sq lServer
To show all the store procedures in a database
SELECT name
FROM sys.objects
WHERE type = 'P'
Following script will provide name of all the stored procedure which were created in last 7 days, they may or may not be modified after that.
-------------------------------------------------------------------------------------
SELECT *
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,create_date,GETDATE()) < 7
FROM sys.objects
WHERE type = 'P'
Following script will provide name of all the stored procedure which were created in last 7 days, they may or may not be modified after that.
-------------------------------------------------------------------------------------
SELECT *
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,create_date,GETDATE()) < 7
Labels:
Sq lServer
Specifiying connection string in Registry
go to start-->Run-->regedit Registory editor opens..
right click on Software and to add new key by name Myproject..(right click software new->key)
then go to Myproject and rightclick to add new key by name proj01(same as above)
after creating the proj01 key ..right click on the right pane to add a string value..to do that
right click on right pane new->string value
here the connection string can be specified in the string value in the "data" column and name as "ConnKey"
" server=192.110.210.34;database=MyDatabase;uid=user01;pwd=user01; "
==============================================================================================
go to web.config
in <appSettings> section write the folowing code
<appSettings>
<add key="RegistryPath" value="SOFTWARE\MyProject\Proj01"/>
</appSettings>
to get the connection string from the registry path
=====================================================
public static string GetConnectionString()
{
string ConnString = string.Empty;
RegistryKey regPath = Registry.LocalMachine.OpenSubKey(ConfigurationManager.AppSettings["RegistryPath"].ToString(), false);
try
{
if (regPath != null)
{
ConnString = regPath.GetValue("ConnKey").ToString();
}
else
{
throw new Exception("Error in establishing Connection with the DataBase");
}
}
catch (Exception e)
{
throw e;
}
return ConnString;
}
right click on Software and to add new key by name Myproject..(right click software new->key)
then go to Myproject and rightclick to add new key by name proj01(same as above)
after creating the proj01 key ..right click on the right pane to add a string value..to do that
right click on right pane new->string value
here the connection string can be specified in the string value in the "data" column and name as "ConnKey"
" server=192.110.210.34;database=MyDatabase;uid=user01;pwd=user01; "
==============================================================================================
go to web.config
in <appSettings> section write the folowing code
<appSettings>
<add key="RegistryPath" value="SOFTWARE\MyProject\Proj01"/>
</appSettings>
to get the connection string from the registry path
=====================================================
public static string GetConnectionString()
{
string ConnString = string.Empty;
RegistryKey regPath = Registry.LocalMachine.OpenSubKey(ConfigurationManager.AppSettings["RegistryPath"].ToString(), false);
try
{
if (regPath != null)
{
ConnString = regPath.GetValue("ConnKey").ToString();
}
else
{
throw new Exception("Error in establishing Connection with the DataBase");
}
}
catch (Exception e)
{
throw e;
}
return ConnString;
}
Thursday, September 10, 2009
Concatinating Multiple column value into a single column
Concatinating Multiple column value into a single column
SELECT a.ID 'PropertyID', a.Heading,RateSummary AS Description,c.propertyphotopath,pm.Photos,
pm.Visitors,pm.Inquiries,pm.PublishedDate,a.ExpiryDate
,Case pm.Photos when 0 then '' else 'Currently with'+' '+convert(varchar(50),pm.Photos)+' '+'Photos' End+','
+Case pm.Inquiries when 0 then '' else convert(varchar(50),pm.Inquiries)+' '+'Inquiries Since'+' '+convert(varchar(50),FirstEnquiryDate,106)+',' End
+Case pm.Visitors when 0 then '' else convert(varchar(50),pm.Visitors)+' '+'Visitors Since'+' '+Convert(varchar(50),FirstVisitedDate,106)+',' end
+Case DATEDIFF(day,,a.ExpiryDate) when 0 then '' else 'Expires in '+ ' '+convert(varchar(50),DATEDIFF(day, a.createdDate,a.ExpiryDate))+' '+'Days on'+' '+convert(varchar(50),a.ExpiryDate,106) end
+case isnull(pm.PublishedDate,0) when 0 then '' else ' '+'First Published on'+convert(varchar(50),pm.PublishedDate,106) end
FROM PropertyInfo a
INNER JOIN RateDetail b ON a.ID = b.PropertyInfoID
LEFT OUTER JOIN photogallery c ON a.ID = c.PropertyInfoID
Inner join propertymetrics pm on a.ID=pm.PropertyInfoID
WHERE c.ISthumbnail = 'TRUE';
SELECT a.ID 'PropertyID', a.Heading,RateSummary AS Description,c.propertyphotopath,pm.Photos,
pm.Visitors,pm.Inquiries,pm.PublishedDate,a.ExpiryDate
,Case pm.Photos when 0 then '' else 'Currently with'+' '+convert(varchar(50),pm.Photos)+' '+'Photos' End+','
+Case pm.Inquiries when 0 then '' else convert(varchar(50),pm.Inquiries)+' '+'Inquiries Since'+' '+convert(varchar(50),FirstEnquiryDate,106)+',' End
+Case pm.Visitors when 0 then '' else convert(varchar(50),pm.Visitors)+' '+'Visitors Since'+' '+Convert(varchar(50),FirstVisitedDate,106)+',' end
+Case DATEDIFF(day,,a.ExpiryDate) when 0 then '' else 'Expires in '+ ' '+convert(varchar(50),DATEDIFF(day, a.createdDate,a.ExpiryDate))+' '+'Days on'+' '+convert(varchar(50),a.ExpiryDate,106) end
+case isnull(pm.PublishedDate,0) when 0 then '' else ' '+'First Published on'+convert(varchar(50),pm.PublishedDate,106) end
FROM PropertyInfo a
INNER JOIN RateDetail b ON a.ID = b.PropertyInfoID
LEFT OUTER JOIN photogallery c ON a.ID = c.PropertyInfoID
Inner join propertymetrics pm on a.ID=pm.PropertyInfoID
WHERE c.ISthumbnail = 'TRUE';
Labels:
Sq lServer
To Bind A value from database to button and using that value to redirect in code behind file
Using OnCommand in Button
.aspx page
--------------
<asp:ImageButton ID="img01" runat="server" ImageUrl="~/Images/edit_j_btn.jpg" OnCommand="onEdit_Click" CommandArgument='<%#Eval("UserId") %>' />
code behind
--------------
public void onEdit_Click(object sender,System.Web.UI.WebControls.CommandEventArgs e)
{
int userid= Convert.ToInt32(e.CommandArgument);
Response.Redirect("Home.aspx?_UserId=" + userid);
}
.aspx page
--------------
<asp:ImageButton ID="img01" runat="server" ImageUrl="~/Images/edit_j_btn.jpg" OnCommand="onEdit_Click" CommandArgument='<%#Eval("UserId") %>' />
code behind
--------------
public void onEdit_Click(object sender,System.Web.UI.WebControls.CommandEventArgs e)
{
int userid= Convert.ToInt32(e.CommandArgument);
Response.Redirect("Home.aspx?_UserId=" + userid);
}
Monday, August 31, 2009
Friday, August 28, 2009
Javascript click() does not cause a Response.Redirect in asp.net
JavaScript click() does not cause a Response.Redirect in asp.net
when Page has 2 text box and button pair(ie)one for search and the other for lo gin.
The main problem that's encountered here is when the user enters the user name and password and presses the enter key the lo gin button click event is not called as the search button on top of the page has the default focus.
In HTML there is an option to set default focus and default button.
Defaultbutton as the search button(btnsearch)
and DefaultFocus as search textbox(txtsearch)
in some scenario this may not help.so we go for key press event to capture the "enter key" press
TextMode="Password" TabIndex="1" onkeypress="KeyCheck();" >
//This function will be invoked when the enter key is pressed after keying in user name followed by the password
//if the key pressed is an Enter Key the we are calling the server side button click event..this can be achieved with
//the help of JavaScript "click()" method..
//Click() method calls the button click event in the server side and after performing the operation the control returns back
//to the JavaScript key press event call..in case if we like to redirect to an other page on this click event, we will have
//to cancel the click event in order to redirect.to achieve that " window.event.return Value = false;" this method has to be called
function KeyCheck()
{
if (event.keyCode ==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
window.event.returnValue = false;
}
function KeysCheck(e)
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
alert("ascx");
document.getElementById('ctl00_ContentPlaceHolder1_BasicSearch1_btnSearch').click();
window.event.returnValue = false;
}
}
}
Following Code will check the type of browser and execute accordingly.
function KeyCheck(e)
{
var browserName="";
var ua=navigator.userAgent.toLowerCase();
if ( ua.indexOf( "firefox" ) != -1 )
{
browserName = "firefox";
}
else if ( ua.indexOf( "msie" ) != -1 )
{
browserName = "msie";
}
if(browserName=="firefox")
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
e.preventDefault();
}
}
else if(browserName=="msie")
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
window.event.returnValue = false;
}
}
}
when Page has 2 text box and button pair(ie)one for search and the other for lo gin.
The main problem that's encountered here is when the user enters the user name and password and presses the enter key the lo gin button click event is not called as the search button on top of the page has the default focus.
In HTML there is an option to set default focus and default button.
Defaultbutton as the search button(btnsearch)
and DefaultFocus as search textbox(txtsearch)
in some scenario this may not help.so we go for key press event to capture the "enter key" press
//This function will be invoked when the enter key is pressed after keying in user name followed by the password
//if the key pressed is an Enter Key the we are calling the server side button click event..this can be achieved with
//the help of JavaScript "click()" method..
//Click() method calls the button click event in the server side and after performing the operation the control returns back
//to the JavaScript key press event call..in case if we like to redirect to an other page on this click event, we will have
//to cancel the click event in order to redirect.to achieve that " window.event.return Value = false;" this method has to be called
function KeyCheck()
{
if (event.keyCode ==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
window.event.returnValue = false;
}
function KeysCheck(e)
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
alert("ascx");
document.getElementById('ctl00_ContentPlaceHolder1_BasicSearch1_btnSearch').click();
window.event.returnValue = false;
}
}
}
Following Code will check the type of browser and execute accordingly.
function KeyCheck(e)
{
var browserName="";
var ua=navigator.userAgent.toLowerCase();
if ( ua.indexOf( "firefox" ) != -1 )
{
browserName = "firefox";
}
else if ( ua.indexOf( "msie" ) != -1 )
{
browserName = "msie";
}
if(browserName=="firefox")
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
e.preventDefault();
}
}
else if(browserName=="msie")
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
window.event.returnValue = false;
}
}
}
Labels:
Javascript
Subscribe to:
Posts (Atom)