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;
}

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

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

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>

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>

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!";
}

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

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");

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>

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>