affiliate marketing Dot Net Posts

Sunday, 31 July 2011

Download any file in asp.net with c#

private void Downloadfile()
{
System.IO.FileInfo file = new System.IO.FileInfo(@"D:\csv.csv");

if (file.Exists)
{

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

Response.AddHeader("Content-Length", file.Length.ToString());

Response.ContentType = "application/octet-stream";

Response.WriteFile(file.FullName);

Response.End();

}

}

Saturday, 2 July 2011

Asp Net & Javascript Avoid Multiple Submit (Only Allow Submit 1 Time)

This short tutorial will show you how to avoid multiple submissions from users by give an alert when user click or submit more than 1 time using JavaScript and asp net.
This function are suitable for ecommerce site or any pages that need do some registration or payment and etc.

Example situation, when you do a reservation for a flight and the online reservation service system didn't include the avoid multiple submit and the processing time for flight reservation system take more than your expect. You maybe thought that you didn't submit yet and when you click submit again. Maybe the online reservation system already helps you to book more than 1 ticket.

So, it is important to include this function to avoid you or your customer loose money.

Below is the code for this tutorial:
After you read and please give some comment (good and bad)

Javascript
script language=javascript >
var is_form_submited=0;
function enableJS()
{
document.testing.jsEnabled.value="yes";
return true;
}

function processInput()
{
if (is_form_submited==1)
{
alert("Your request has been submitted. please wait..");
return false;
}

enableJS();
is_form_submited=1;
return true;
}


.ASPX page

form id="testing" runat="server" onsubmit="processInput()">
asp:Button ID="Button1" runat="server" Text="Submit" />
input type="hidden" name="jsEnabled" value="no" />




.VB Code Behind Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Attributes.Add("onclick", "enableJS()")
End Sub

write some disadvantage of cursor ?

Cursor plays there row quite nicely but although there are some disadvantage of Cursor .
Because we know cursor doing roundtrip it will make network line busy and also make time consuming methods. First of all select query gernate output and after that cursor goes one by one so roundtrip happen.Another disadvange of cursor are ther are too costly because they require lot of resources and temporary storage so network is quite busy.

Multiple email validation seperated by comma using javascript


function echeck(str) 


var at="@"; 
var dot="."; 
var lat=str.indexOf(at); 
var lstr=str.length; 
var ldot=str.indexOf(dot); 
if (str.indexOf(at)==-1) 

alert("Invalid E-mail ID"); 
return false; 


if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) 

alert("Invalid E-mail ID:"+str+""); 
return false; 


if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) 

alert("Invalid E-mail ID:"+str+""); 
return false; 


if (str.indexOf(at,(lat+1))!=-1) 

alert("Invalid E-mail ID:"+str+""); 
return false; 


if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) 

alert("Invalid E-mail ID:"+str+""); 
return false; 


if (str.indexOf(dot,(lat+2))==-1) 

alert("Invalid E-mail ID:"+str+""); 
return false; 


if (str.indexOf(" ")!=-1) 

alert("Invalid E-mail ID"); 
return false; 


return true; 


function LTrim( value ) 


var re = /\s*((\S+\s*)*)/; 
return value.replace(re, "$1"); 



// Removes ending whitespaces 
function RTrim( value ) 


var re = /((\s*\S+)*)\s*/; 
return value.replace(re, "$1"); 



// Removes leading and ending whitespaces 
function trim( value ) 


return LTrim(RTrim(value)); 


Here : take 
function checkMailIds(id,id2) 


debugger; 
var cnt=0; 
var mailids=id.value; 
var str=mailids.split(","); 

for(var i=0;i{
var obk=str[i];
var obk=trim(obk);
//alert(obk);
if(echeck(obk)==false)
{

id2.disabled=true;
return false;

}
else
{

cnt=parseInt(cnt)+1;
if(cnt==str.length)
{

id2.disabled=false;
return true;
}

//return true;
}



}

}

function chktxt()
{

var txtemail=document.getElementById('txtemail');
if(txtemail.value=="")
{
alert("Enter Emailid");
return false;
}
else
{
return true;
}

Primary Key,Candidate key,Foreign key


RDBMS FUNDAMENTALS - Identifiers for Relations

Identifiers for Relations :
Primary Key : An attribute that uniquely identifies a row in a table is called its primary key. A relation can have only one primary key. The primary key cannot have any null values. In case no unique key is found in a relation, two or more attributes can be treated as the primary key. Such keys are called Composite Keys.
Candidate Key : A relation can have more than one attribute that uniquely identifies a tuple. Any one of these keys can be selected as the primary key. All such attributes are called Candidate Keys. All candidate keys that are not primary keys are called Alternate Keys.
Foreign Key : An attribute that is not a candidate key is called a Nonkey. A nonkey attribute of a relation whose value matches the primary key in some other table is called Foreign Key OR is a column in a table that uniquely identifies rows from a different table.

Using CTE and Row_Number() to get the duplicate data in SQL Server 2005


This is the script to get the duplicate data from employee table, whose employee name is repeating.


With TestData as

(

Select

EmployeeId,

Row_Number() Over( Partition By EmployeeName Order By EmployeeName) AS Rowid

From

Employees

)

Select EmployeeId from TestData Where RowId > 1

Friday, 24 June 2011

Save multiples values into table in sql server using function

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE FUNCTION [dbo].[Fxn_Global_SeperatedValues]
(@values varchar(Max) )
RETURNS @um_temp Table (person_id int)
AS
Begin
DECLARE @NextString VARCHAR(100)
DECLARE @Pos INT
DECLARE @Delimiter VARCHAR(10)
SET @Delimiter = ','
--SET @Values = @Values + @Delimiter
SET @Pos = CHARINDEX(@Delimiter,@Values)
WHILE (@pos <> 0)
BEGIN
SET @NextString = substring(@Values,1,@Pos - 1)
insert into @um_temp (person_id) values(@NextString)
SET @Values = substring(@Values,@pos+1,len(@Values))
SET @pos = charindex(@Delimiter,@Values)
End
return
End