<head>
<title>Limit Number of Characters in a TextArea</title>
<script type='text/javascript'>
src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
$('.cssclassname').keyup(function() {
var len = this.value.length;
if (len >= 150) {
this.value = this.value.substring(0, 150);
}
$('#charLeft').text(150 - len);
});
});
</script>
</head>
Tuesday, July 17, 2012
Saturday, March 10, 2012
change the same column names in all tables using cursors
Create procedure [dbo].[sp_RenameColumName]
@OldColumnName nvarchar(200),
@NewColumnName nvarchar(200)
as
Declare @column_name nvarchar(200)
DECLARE db_cursor CURSOR FOR
SELECT
(t.name+'.'+c.name) AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%'+@OldColumnName+'%'
Begin
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @column_name
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_rename @column_name,@NewColumnName, 'COLUMN'
FETCH NEXT FROM db_cursor into @column_name
END
CLOSE db_cursor
DEALLOCATE db_cursor
End
@OldColumnName nvarchar(200),
@NewColumnName nvarchar(200)
as
Declare @column_name nvarchar(200)
DECLARE db_cursor CURSOR FOR
SELECT
(t.name+'.'+c.name) AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%'+@OldColumnName+'%'
Begin
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @column_name
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_rename @column_name,@NewColumnName, 'COLUMN'
FETCH NEXT FROM db_cursor into @column_name
END
CLOSE db_cursor
DEALLOCATE db_cursor
End
Wednesday, March 7, 2012
Create a Business Logic Layer, Data Access Layer classes, and Stored Procedure scripts from a database table
follow following link:
http://www.codeproject.com/Articles/85482/Create-a-Business-Logic-Layer-Data-Access-Layer-cl
http://www.codeproject.com/Articles/85482/Create-a-Business-Logic-Layer-Data-Access-Layer-cl
Monday, February 27, 2012
Display Image in Image Control while Uploading Image Using FileUpload Control
Source File Code:
<script type="text/javascript">
function UploadImage()
{
document.getElementById('<%=BtnTemp.ClientID %>').click();
}
</script>
<asp:Image ID="Image1" runat="server" Height="97px" Width="130px" />
<asp:FileUpload ID="FileUpload1" OnChange="return UploadImage();" runat="server"
/> <div id="hide" style="display:none">
<asp:Button ID="BtnTemp" runat="server" OnClick="BtnTemp_Click" />
</div>
.Cs file Code:
protected void BtnTemp_Click(object sender, EventArgs e)
{
string FileName = FileUpload1.FileName;
string GudID = Guid.NewGuid().ToString();
string fullname = GudID +"_"+ FileName;
FileUpload1.SaveAs(Server.MapPath("~/Images/" + fullname));
Image1.ImageUrl = "~/Images/" + fullname;
}
<script type="text/javascript">
function UploadImage()
{
document.getElementById('<%=BtnTemp.ClientID %>').click();
}
</script>
<asp:Image ID="Image1" runat="server" Height="97px" Width="130px" />
<asp:FileUpload ID="FileUpload1" OnChange="return UploadImage();" runat="server"
/> <div id="hide" style="display:none">
<asp:Button ID="BtnTemp" runat="server" OnClick="BtnTemp_Click" />
</div>
.Cs file Code:
protected void BtnTemp_Click(object sender, EventArgs e)
{
string FileName = FileUpload1.FileName;
string GudID = Guid.NewGuid().ToString();
string fullname = GudID +"_"+ FileName;
FileUpload1.SaveAs(Server.MapPath("~/Images/" + fullname));
Image1.ImageUrl = "~/Images/" + fullname;
}
Wednesday, February 22, 2012
Generate Unique Identity Value Using Datepart in SQLServer :
create procedure SP_Insert_Customer
as
begin
declare @CustomerID nvarchar(50)
set @CustomerID=CONVERT(nvarchar(10),DATEPART(MM,getdate()))+ CONVERT(nvarchar(10),DATEPART(YYYY,getdate()))
+ CONVERT(nvarchar(10),(select COUNT(*) from dbo.Users)+ 1)
print(@ID);
end
O/P:220124 i.e Month Year Number of rows in the table
as
begin
declare @CustomerID nvarchar(50)
set @CustomerID=CONVERT(nvarchar(10),DATEPART(MM,getdate()))+ CONVERT(nvarchar(10),DATEPART(YYYY,getdate()))
+ CONVERT(nvarchar(10),(select COUNT(*) from dbo.Users)+ 1)
print(@ID);
end
O/P:220124 i.e Month Year Number of rows in the table
Monday, February 20, 2012
Get Identity column value after Inserting the record into Database Table
Create procedure [dbo].[SP_Insert_Employee]
@EmpId int output,
@Name nvarchar(50),
@Address nvarchar(50),
as
begin
insert into dbo.Employee(Name,Address) values(@Name,@Address )
set @EmpId=SCOPE_IDENTITY();
end
@EmpId int output,
@Name nvarchar(50),
@Address nvarchar(50),
as
begin
insert into dbo.Employee(Name,Address) values(@Name,@Address )
set @EmpId=SCOPE_IDENTITY();
end
Thursday, February 16, 2012
Hide part webpage when the webpage was printing
PrintForm = function (strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=480,height=400,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}
Here’s the webpage, the printable area must be inside a div:
<div id="divPrint">
SAMPLE CONTENT
</div>
<input id="btnPrintBottom" type="button" value="Print" onclick="PrintForm('divPrint')" />
Print button hiding:
document.getElementById('Button').style.visibility = "hidden";
Display TextBox data into Label :
var b = document.getElementById('<%=TextBox1.ClientID %>').value;
document.getElementById('lb').style.display = "block";
var c = document.getElementById('<%=lblName.ClientID %>').innerText= b.toString();
Wednesday, February 15, 2012
Copy data from one Textbox to another Textbox while User entering data
on the keypress event of the textbox write the following code
document.getElementByID('<%=TextBox2.ClientID%>').Text = document.getElementByID('<%=TextBox1.ClientID%>').Text <asp:textbox id="TextBox" runat=server onkeypress="document.getElementByID('<%=TextBox2.ClientID%>').Text = document.getElementByID('<%=TextBox1.ClientID%>').Text"> </asp:textbox> onblur event of the textbox write the following code //javaScript function fnFromToTextBox(firstTxtBox,secondTxtBox) { secondTxtBox.value=firstTxtBox.value; } //on Code behind txtCompany.Attributes.Add("onblur", "fnFromToTextBox(txtCompany,txtBilling)"); Using Keyup: <asp:TextBox id="TextBox1" onkeyup="document.getElementById("TextBox2").value = this.value;"></asp:TextBox>
document.getElementByID('<%=TextBox2.ClientID%>').Text = document.getElementByID('<%=TextBox1.ClientID%>').Text <asp:textbox id="TextBox" runat=server onkeypress="document.getElementByID('<%=TextBox2.ClientID%>').Text = document.getElementByID('<%=TextBox1.ClientID%>').Text"> </asp:textbox> onblur event of the textbox write the following code //javaScript function fnFromToTextBox(firstTxtBox,secondTxtBox) { secondTxtBox.value=firstTxtBox.value; } //on Code behind txtCompany.Attributes.Add("onblur", "fnFromToTextBox(txtCompany,txtBilling)"); Using Keyup: <asp:TextBox id="TextBox1" onkeyup="document.getElementById("TextBox2").value = this.value;"></asp:TextBox>
Tuesday, February 14, 2012
textbox validation Using JQuery
<script language="javascript" type="text/javascript">
$(document).ready(function ()
{
$("#<% =btnSubmit.ClientID %>").click(function ()
{
if (jQuery.trim($("#<%=txtBranchCode.ClientID %>").val()) == "")
{
alert("Please enter branch code..");
$("#<%=txtBranchCode.ClientID %>").focus();
return false;
} });
$("#<% =btnCancel.ClientID %>").click(function ()
{
$("#<%=txtBranchCode.ClientID %>").val("");
return false;
});
});
</script>
$(document).ready(function ()
{
$("#<% =btnSubmit.ClientID %>").click(function ()
{
if (jQuery.trim($("#<%=txtBranchCode.ClientID %>").val()) == "")
{
alert("Please enter branch code..");
$("#<%=txtBranchCode.ClientID %>").focus();
return false;
} });
$("#<% =btnCancel.ClientID %>").click(function ()
{
$("#<%=txtBranchCode.ClientID %>").val("");
return false;
});
});
</script>
Monday, February 13, 2012
Image Upload Local folder(project folder) and Save image path into data baes
string onlyname = string.Empty;
int isExist;
if (imgupload.HasFile)
{
string categoryname = txtCategoryName.Text;
string imagename = categoryname.Replace(" ", "");
imagename= imagename + "_Left";
string filePath = imgupload.FileName;
string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1);
string[] filetype = filename.Split('.');
onlyname = imagename + "." + filetype[1];
imgupload.SaveAs(Server.MapPath("~/images/inner/") + onlyname);
lblmsg.Text = "Upload status: File uploaded!";
}
int isExist;
if (imgupload.HasFile)
{
string categoryname = txtCategoryName.Text;
string imagename = categoryname.Replace(" ", "");
imagename= imagename + "_Left";
string filePath = imgupload.FileName;
string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1);
string[] filetype = filename.Split('.');
onlyname = imagename + "." + filetype[1];
imgupload.SaveAs(Server.MapPath("~/images/inner/") + onlyname);
lblmsg.Text = "Upload status: File uploaded!";
}
Saturday, February 11, 2012
Custom Auto-Generated Sequences with SQL Server
Let's start with the simple "C0000" - "C9999" example. First, let's create our Customers table like this:
create table Customers
(
dbID int identity not null primary key,
CustomerName varchar(100)
)
Note that the dbID column is standard, database-generated identity which will be our
physical primary key of the table. However, we will add a CustomerNumber column
which will be what we expose to the outside world in the "C0000" format, as described.
Let's create a function accepts an integer, and uses that integer to return our CustomerNumber:
create function CustomerNumber (@id int)
returns char(5)
as
begin
return 'C' + right('0000' + convert(varchar(10), @id), 4)
end
Using that function, we can simply add a computed column to our table like this:
alter table Customers add CustomerNumber as dbo.CustomerNumber(dbID)
Or, we could also create a column in our table to store the Customer Number,
and use a trigger to populate it:
alter Customers add CustomerNumber varchar(10)
create trigger Customers_insert on Customers
after insert as
update
Customers
set
Customers.customerNumber = dbo.CustomerNumber(Customers.dbID)
from
Customers
inner join
inserted on Customers.dbID= inserted.dbID
Using either method, once they are in place, we can simply
insert into our table, and for each Row added a unique "Customer Number" is assigned:
insert into Customers (CustomerName) values ('jeff')
select * from Customers
returns:
(1 row(s) affected)
dbID CustomerName CustomerNumber
----------- ------------ --------------
1 jeff C0001
(1 row(s) affected)
Follow this link:
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
create table Customers
(
dbID int identity not null primary key,
CustomerName varchar(100)
)
Note that the dbID column is standard, database-generated identity which will be our
physical primary key of the table. However, we will add a CustomerNumber column
which will be what we expose to the outside world in the "C0000" format, as described.
Let's create a function accepts an integer, and uses that integer to return our CustomerNumber:
create function CustomerNumber (@id int)
returns char(5)
as
begin
return 'C' + right('0000' + convert(varchar(10), @id), 4)
end
Using that function, we can simply add a computed column to our table like this:
alter table Customers add CustomerNumber as dbo.CustomerNumber(dbID)
Or, we could also create a column in our table to store the Customer Number,
and use a trigger to populate it:
alter Customers add CustomerNumber varchar(10)
create trigger Customers_insert on Customers
after insert as
update
Customers
set
Customers.customerNumber = dbo.CustomerNumber(Customers.dbID)
from
Customers
inner join
inserted on Customers.dbID= inserted.dbID
Using either method, once they are in place, we can simply
insert into our table, and for each Row added a unique "Customer Number" is assigned:
insert into Customers (CustomerName) values ('jeff')
select * from Customers
returns:
(1 row(s) affected)
dbID CustomerName CustomerNumber
----------- ------------ --------------
1 jeff C0001
(1 row(s) affected)
Follow this link:
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
Thursday, February 9, 2012
Binding data to Dropdown list In asp.net
1.get the data from data base and we can attach data to dropdown as follows
2.Inserting the "select" Ist Item to the Dropdownlist
Here DataTextField and DataValueField taken from the database attached to dropdown list
ddlcategory.DataSource = objCategoryBLL.GetAllCategories().Tables[0];
ddlcategory.DataTextField = "CatgName";
ddlcategory.DataValueField = "CatgId";
ddlcategory.DataBind();
ddlcategory.Items.Insert(0, "Select");
Here DataTextField and DataValueField taken from the database attached to dropdown list
ddlcategory.DataSource = objCategoryBLL.GetAllCategories().Tables[0];
ddlcategory.DataTextField = "CatgName";
ddlcategory.DataValueField = "CatgId";
ddlcategory.DataBind();
ddlcategory.Items.Insert(0, "Select");
Hide/Show div using JavaScript Code
I taken Two div's as follows
and I hide/show from server side client call i.e Script manager
<div id="Status" style="display:none">
<tr><td align="right" width="175px"><asp:Label ID="lblStatus" runat="server" Text="Status"></asp:Label></td>
</div>
<div id="Status1" style="display:none">
<tr><td align="right" width="175px"><asp:Label ID="lblStatus1" runat="server" Text="Status1"></asp:Label></td>
</div>
ScriptManager.RegisterStartupScript(this, this.GetType(), "status", "javascript:Status();", true);
<script type="text/javascript">
function Status()
{
document.getElementById('Status').style.display = "block";
document.getElementById('Status1').style.display = "none";
}
</script>
and I hide/show from server side client call i.e Script manager
<div id="Status" style="display:none">
<tr><td align="right" width="175px"><asp:Label ID="lblStatus" runat="server" Text="Status"></asp:Label></td>
</div>
<div id="Status1" style="display:none">
<tr><td align="right" width="175px"><asp:Label ID="lblStatus1" runat="server" Text="Status1"></asp:Label></td>
</div>
ScriptManager.RegisterStartupScript(this, this.GetType(), "status", "javascript:Status();", true);
<script type="text/javascript">
function Status()
{
document.getElementById('Status').style.display = "block";
document.getElementById('Status1').style.display = "none";
}
</script>
Wednesday, February 8, 2012
Accepting 5digit numder using javascript code
<asp:TextBox ID="TextBox1" Width="250Px" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClientClick="javascript:validateZipCode()" Text="Button" />
JavaScript Code:
<script type="text/javascript">
function validateZipCode()
{
var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
var elementValue=document.getElementById('<%=TextBox1.ClientID %>').value
if (elementValue.search(zipCodePattern) == -1)
{
alert('please enter valid 5 dit num')
}
}
</script>
<asp:Button ID="Button1" runat="server" OnClientClick="javascript:validateZipCode()" Text="Button" />
JavaScript Code:
<script type="text/javascript">
function validateZipCode()
{
var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
var elementValue=document.getElementById('<%=TextBox1.ClientID %>').value
if (elementValue.search(zipCodePattern) == -1)
{
alert('please enter valid 5 dit num')
}
}
</script>
Friday, January 27, 2012
WCF Service Host in asp.net
IIS 7 Hosting
The main advantage of hosting service in IIS is that, it will automatically launch the host process when it gets the first client request. It uses the features of IIS such as process recycling, idle shutdown, process health monitoring and message based activation. The main disadvantage of using IIS is that, it will support only HTTP protocol.
Let as do some hands on, to create service and host in IIS
Step 1:Start the Visual Studio 2008 and click File->New->Web Site. Select the 'WCF Service' and Location as http. This will directly host the service in IIS and click OK. (create one folder in physical location i.e D:\IISHostService next create one website in IIS and map this folder to IIS website)
Step 2: I have created sample HelloWorld service, which will accept name as input and return with 'Hello' and name. Interface and implementation of the Service is shown below.
IMyService.cs
[ServiceContract]
public interface IMyService
{
[OperationContract]
string HelloWorld(string name);
}
MyService.cs
public class MyService : IMyService
{
#region IMyService Members
public string HelloWorld(string name)
{
return "Hello " + name;
}
#endregion
}
Step 3: Service file (.svc) contains name of the service and code behind file name. This file is used to know about the service.
MyService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
Step 4: Server side configurations are mentioned in the config file. Here I have mention only one end point which is configured to 'wsHttpBinding', we can also have multiple end point with differnet binding. Since we are going to hosted in IIS. We have to use only http binding. We will come to know more on endpoints and its configuration in later tutorial. Web.Config
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyService">
<endpoint address="http://localhost:9703/IISHostedService/MyService.svc"
binding="wsHttpBinding" contract="IMyService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the
metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for
debugging purposes, set the value below to true.
Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Note:
You need to mention the service file name, along with the Address mention in the config file. IIS Screen shot
This screen will appear when we run the application.
Step 1:Start the Visual Studio 2008 and click File->New->Web Site. Select the 'WCF Service' and Location as http. This will directly host the service in IIS and click OK. (create one folder in physical location i.e D:\IISHostService next create one website in IIS and map this folder to IIS website)
Step 2: I have created sample HelloWorld service, which will accept name as input and return with 'Hello' and name. Interface and implementation of the Service is shown below.
IMyService.cs
[ServiceContract]
public interface IMyService
{
[OperationContract]
string HelloWorld(string name);
}
MyService.cs
public class MyService : IMyService
{
#region IMyService Members
public string HelloWorld(string name)
{
return "Hello " + name;
}
#endregion
}
Step 3: Service file (.svc) contains name of the service and code behind file name. This file is used to know about the service.
MyService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
Step 4: Server side configurations are mentioned in the config file. Here I have mention only one end point which is configured to 'wsHttpBinding', we can also have multiple end point with differnet binding. Since we are going to hosted in IIS. We have to use only http binding. We will come to know more on endpoints and its configuration in later tutorial. Web.Config
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyService">
<endpoint address="http://localhost:9703/IISHostedService/MyService.svc"
binding="wsHttpBinding" contract="IMyService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the
metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for
debugging purposes, set the value below to true.
Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Note:
You need to mention the service file name, along with the Address mention in the config file. IIS Screen shot
This screen will appear when we run the application.
Thursday, January 26, 2012
How to write html/javascript code in blogger blog post?
How to write html/javascript code in blogger blog post?
write html/javascript code in blogger blog postIf you have ever tried writing HTML/Javascript code in your blogger blog post then you might have found that it does not appear as code in the post. Instead the code is interpreted and displayed.
The above problem can be simply fixed by replacing < with "Ampersand(&)lt;" and > by "Ampersand(&)gt;" . Here we are providing a few elegant ways to do this.
We will start with the toughest one first. If you like easy things just skip to the last step.
Method 1 Open notepad and paste your code in it. Hit ctrl+h or choose Edit > Replace In Find what: box type < and in Replace with: box type "Ampersand(&)lt;" and hit Replace all button Similarly for > type > in Find what: box and "Ampersand(&)gt;" in Replace with: box. Your are done, the code is ready to be used in your post.
Method 2 Paste your code in the text box below and hit Convert button. Done! Your code is ready to be pasted in your blogger blog post. For easy access we suggest that you bookmark (ctrl+d) this page.
Method 3 The above method requires you to visit this page whenever you want to convert your code. This is waste of time and will also require your to have an active internet connection. Let's make things a bit easier download html converter now.
Method 4 The next method is the official solution from blogger. If you need to write html code in your post just select post options and in compose settings choose Show HTML literally. Any code now written will not be interpreted as HTML.
follow following link: http://bloggerfunda.blogspot.com/2009/11/how-to-write-htmljavascript-code-in.html
Method 1 Open notepad and paste your code in it. Hit ctrl+h or choose Edit > Replace In Find what: box type < and in Replace with: box type "Ampersand(&)lt;" and hit Replace all button Similarly for > type > in Find what: box and "Ampersand(&)gt;" in Replace with: box. Your are done, the code is ready to be used in your post.
Method 2 Paste your code in the text box below and hit Convert button. Done! Your code is ready to be pasted in your blogger blog post. For easy access we suggest that you bookmark (ctrl+d) this page.
Method 3 The above method requires you to visit this page whenever you want to convert your code. This is waste of time and will also require your to have an active internet connection. Let's make things a bit easier download html converter now.
Method 4 The next method is the official solution from blogger. If you need to write html code in your post just select post options and in compose settings choose Show HTML literally. Any code now written will not be interpreted as HTML.
follow following link: http://bloggerfunda.blogspot.com/2009/11/how-to-write-htmljavascript-code-in.html
Wednesday, January 25, 2012
Grideview DataKeys in Asp.net Using C# code
GrideviewName.DataKeyNames = new string[] { "pid", "catId" };
OR
mension datakeys in the source code like in the Gridtag
asp:gridview DataKeyNames=pid,catId
In the above we are given datakeys names pid,catId
Get Datakeys values(pid,catId):
GridviewName.DataKeys[e.RowIndex].Values["Pid"]);
GridviewName.DataKeys[e.RowIndex].Values["catId"]);
OR
mension datakeys in the source code like in the Gridtag
asp:gridview DataKeyNames=pid,catId
In the above we are given datakeys names pid,catId
Get Datakeys values(pid,catId):
GridviewName.DataKeys[e.RowIndex].Values["Pid"]);
GridviewName.DataKeys[e.RowIndex].Values["catId"]);
Grid view Row Updation using Onblur event of TextBox in Javascript
Note:if you want Update gridview row when you changing the text in the textbox and you click on the out gridview or on the grideview
you can written Onblur event of textbox.
Ex:I update Quantity in the textbox by click on the webpage or gridview.
I written Onblur() event in the textbox as follows.this will call server side code
function changeQuantity(obj) {
if (obj.value == 0)
obj.value = 1;
document.getElementById('<%= ButtonName.ClientID %>').click();
server side Code:
protected void btnCheck_OnClick(object sender, EventArgs e)
{
foreach (GridViewRow item in GVCart.Rows)
{
string lPid = Convert.ToString(GVCart.DataKeys[item.RowIndex].Values["pid"]);
TextBox lQty = (TextBox)item.FindControl("txtQty");
}
}
TextBox event Onblur Is:
onblur="changeQuantity(this)"
you can written Onblur event of textbox.
Ex:I update Quantity in the textbox by click on the webpage or gridview.
I written Onblur() event in the textbox as follows.this will call server side code
function changeQuantity(obj) {
if (obj.value == 0)
obj.value = 1;
document.getElementById('<%= ButtonName.ClientID %>').click();
server side Code:
protected void btnCheck_OnClick(object sender, EventArgs e)
{
foreach (GridViewRow item in GVCart.Rows)
{
string lPid = Convert.ToString(GVCart.DataKeys[item.RowIndex].Values["pid"]);
TextBox lQty = (TextBox)item.FindControl("txtQty");
}
}
TextBox event Onblur Is:
onblur="changeQuantity(this)"
Enter numbers only in TextBox using javascript code
function onlynumbers(event) {
if (event.keyCode == 46 || event.keyCode == 8) {
return true;
}
else {
// Ensure that it is a number and stop the keypress
if ((event.keyCode < 48 || event.keyCode > 57)) {
alert('enter only numbers....');
return false;
}
else {
return true;
}
}
this function can be written the the TextBox keypress event like
onkeypress="return onlynumbers(event)"
if (event.keyCode == 46 || event.keyCode == 8) {
return true;
}
else {
// Ensure that it is a number and stop the keypress
if ((event.keyCode < 48 || event.keyCode > 57)) {
alert('enter only numbers....');
return false;
}
else {
return true;
}
}
this function can be written the the TextBox keypress event like
onkeypress="return onlynumbers(event)"
Tuesday, January 24, 2012
Monday, January 23, 2012
Email validation using Java Script
function validate()
{
var emailformat = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/ //regular expression defining a 8 digit number
var email = document.getElementById('<%=txtEmail.ClientID %>').value;
if (email == "") {
alert('Enter emailid...');
return false;
document.getElementById('<%=txtEmail.ClientID %>').focus();
}
if (email.search(emailformat) == -1) { //if match failed
alert("please enter valid emailid...");
return false;
document.getElementById('<%=txtEmail.ClientID %>').focus();
}
}
Call this function in OnClientClick of Button like
OnClientClick="javascript:return validate();"
{
var emailformat = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/ //regular expression defining a 8 digit number
var email = document.getElementById('<%=txtEmail.ClientID %>').value;
if (email == "") {
alert('Enter emailid...');
return false;
document.getElementById('<%=txtEmail.ClientID %>').focus();
}
if (email.search(emailformat) == -1) { //if match failed
alert("please enter valid emailid...");
return false;
document.getElementById('<%=txtEmail.ClientID %>').focus();
}
}
Call this function in OnClientClick of Button like
OnClientClick="javascript:return validate();"
Wednesday, January 4, 2012
Clear/Remove QueryString value in asp.net
In general query string not clear using following
Request.QueryString.Remove("id");
Request.QueryString.Clear();
you get error like Collection readolny
but we can solve this following code
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
// remove
this.Request.QueryString.Remove("id");
Request.QueryString.Remove("id");
Request.QueryString.Clear();
you get error like Collection readolny
but we can solve this following code
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
// remove
this.Request.QueryString.Remove("id");
Subscribe to:
Posts (Atom)