Wednesday, December 29, 2010

Confirmation Message Box For Button or LinkButton ...etc

script language="javascript" type="text/javascript">
function cof()
{
var answer = confirm("Are you sure you want to delete this page?")
if (answer)
{
alert("Successfully Deleted the page.")
document.getElementById("<%=HiddenField1.ClientID%>").value='1';
}
else {

document.getElementById("<%=HiddenField1.ClientID%>").value='2';
// window.location.href = "MessageBxTest.aspx"
}
}
/script>


---------------------------
asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" OnClientClick="cof()" >Delete /asp:LinkButton>
asp:Label ID="Label1" runat="server" Text="">/asp:Label>
asp:HiddenField ID="HiddenField1" runat="server" />


Code Part
---------------------------
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (HiddenField1.Value == "1")
{
Label1.Text = "Delete Successssssss";
}
}

Tuesday, December 21, 2010

Regular Expression For Double Value

[0-9]+(\.[0-9][0-9])?
Ex : 0.11,11,1.11

----------------javascript function for custom validator control------------------
function check() {
var regx = /^([-]?)([0-9]+)((.[0-9]{2})?)$/;
var m = regx.test(document.all.txt.value);
if (m == true) {
alert("right");
}
else {
alert("error");
}
}

Getting 'connection reset by server' error in asp.net mvc upload file code after submit.

Add this in web config
System.Web>
httpRuntime maxRequestLength="value in kilobytes" />
System.Web>

Monday, November 22, 2010

Regular expression to allow numbers between 1 and 100

Here it is:

^([1-9]|[1-9]\d|100)$

If you dont need 100 in range then expression will be this:

^([1-9]|[1-9]\d)$

Thursday, November 11, 2010

Regular expression for validating Date format dd/MM/yyyy

Hi

Use this following Regular Expression Details, This will support leap year also.

^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$


Matches
[29/02/2000], [30/04/2003], [01/01/2003]

Non-Matches
[29/02/2001], [30-04-2003], [1/1/1899]

Wednesday, November 10, 2010

Regular Expression for Email ID

Regular Expression for Email ID

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Sunday, November 7, 2010

Page index changing in gridview

in gridview1_pageindexchanging(......)
{
gridview1.pageindex=e.newpageindex;
fillgrid();
}

Wednesday, November 3, 2010

Login Page Crawling & Indexing by Search Engines - Solution

Please insert below tag in all login pages to make our site more SEO friendly


META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

Tuesday, November 2, 2010

Ajax Pop up message

Use the following code for the pop up message.

aspx

asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="True" />

asp:Panel ID="Panel1" runat="server">

asp:UpdatePanel id="UpdatePanel2" runat="server">

ContentTemplate>





/ContentTemplate>

/asp:UpdatePanel>

/asp:Panel>

aspx.cs

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Thanks for contacting DGP CONTRACTING.');", true);

ItemCommand events not firing for datalist

Here is a very famous issue which almost every developer goes through: assume we have a databound control like a DataList/DataGrid with a nested Button inside it. We want to handle the Button's click event in our code. We can easily to so using OnItemCommand method which raises ItemCommand event. We need to attach an event handler to this in our code.

The problem crops up when we tyr to bind data on every postback, like:

page_load()
{
//..code//
BindDataControl();
}

Now, when the button control is clicked in the datalist/datagrid, it submits the form causing a postback. In the page_load the databind occurs again and all the information about any attached event handlers is lost as the control is bounded again which means that the nested button control will be re-created. This will cause the ItemCommand event handler not to fire.

Simple solution to this problem is to avoid re-binding of data on postback. For e.g.:

page_load()
{
//..code//
if(!IsPostBack)
{
BindDataControl();
}
}

This will make sure that nested controls are not re-created each time on postback and their "state" is maintained. This makes sure that the ItemCommand event handler is fired when ever the Button control is clicked.

Monday, October 25, 2010

To Open a page in new tab

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "New Window", "javascript:window.open('Thanks.aspx')", true);

make hyperlink open in new tab

just insert target="_blank" in that tag like this:

asp:HyperLink ID="hyp" NavigateUrl="~/aboutus.aspx" runat="server" Text="click" Target="_blank"> asp:HyperLink>

Tuesday, October 19, 2010

Selecting Grid Value in RowEditing , RowDeleting,SelectedIndexChanging ് Event

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
string str = GridView1.Rows[e.NewEditIndex].Cells[1].Text;
}


RowDeleting
------------------------------
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string str = GridView1.Rows[e.RowIndex].Cells[1].Text;
}


SelectedIndexChanging Event
----------------------------
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string str = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
}

To get Grid Selected RowIndex and Template Controls in DropDownList SelectedIndex Event

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = ((DropDownList)sender).Parent.Parent as GridViewRow;

int gvrO = Convert.ToInt32(row.RowIndex);

DropDownList ddltest = new DropDownList();
ddltest = (DropDownList)row.FindControl("ddlTest");
string ss = ddltest.SelectedItem.Text;
}

Find Grid Template Controls in Template Combo SelectedIndexChange Event

foreach (GridViewRow gvrow in GridView1.Rows )
{
DropDownList ddltest = new DropDownList();
ddltest = (DropDownList)gvrow.FindControl("ddlTest");
string ss = ddltest.SelectedItem.Text;
}

Thursday, October 14, 2010

Preventing browser back button functionality

In page load event ,b4 if(!ispostback) checking
------------------------------------------------

public void AvoidCache()

{

Response.Cache.SetNoStore();

Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Cache.SetValidUntilExpires(false);

}





OR





put this code in B4 the header tag in Default.aspx page.

------------------------------------------------------------



script type = "text/javascript" > //script for preventing browser back button functionality(Akbar)

function preventBack() { window.history.forward(); }

setTimeout("preventBack()", 0);

window.onunload = function() { null };

/script>

Tuesday, March 30, 2010

Programmatic access to sqldatasource dataset

You can certainly do something like this. I programmatically created an SqlDataSource,
called the Select Method on it, retrieved the DataView, and converted the results to
a DataTable that I can manipulate as I see fit.



string connectionString = "...Northwind Connection String...";
string selectSql = "SELECT [CategoryID], [CategoryName] FROM [Categories]";

DataSourceSelectArguments args = new DataSourceSelectArguments();

SqlDataSource dataSource = new SqlDataSource(connectionString, selectSql);
DataView view = (DataView)dataSource.Select(args);

DataTable table = view.ToTable();

Saturday, March 20, 2010

Info Class

public class CustomerInfo
{
private int _customerid;
private string _firstname;
private string _surname;
private string _customeraddress;
private string _customertelephone;
private string _customermobile;
private string _customeremail;
private int _addressproofid;
private string _addressproofname;
private int _idproofid;
private string _idproofname;
private Boolean _cflag;

public int CustomerId
{
get { return _customerid; }
set { _customerid = value; }
}
public string FirstName
{
get { return _firstname; }
set { _firstname = value; }
}
public string SurName
{
get { return _surname; }
set { _surname = value; }
}
public string CustomerAddrees
{
get { return _customeraddress; }
set { _customeraddress = value; }
}
public string CustomerTelephone
{
get { return _customertelephone; }
set { _customertelephone = value; }
}
public string CustomerMobile
{
get { return _customermobile; }
set { _customermobile = value; }
}
public string CustomerEmail
{
get{return _customeremail;}
set{_customeremail=value;}
}
public int AddressProofId
{
get{return _addressproofid;}
set{_addressproofid=value;}
}
public string AddressProofName
{
get{return _addressproofname;}
set{_addressproofname=value;}
}
public int IdProofId
{
get{return _idproofid;}
set{_idproofid=value;}
}
public string IdProofName
{
get { return _idproofname; }
set { _idproofname = value; }
}

public Boolean CFlag
{
get { return _cflag; }
set { _cflag = value; }
}

}

SP Class

using System.Data.SqlClient;
using System.Windows.Forms;


public class CustomerSP:DBConnection
{
public void AddDetails(CustomerInfo cinfo)
{
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("AddCustomer", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = cinfo.CustomerId;
par = cmd.Parameters.Add("@firstname", SqlDbType.VarChar);
par.Value = cinfo.FirstName;
par = cmd.Parameters.Add("@surname", SqlDbType.VarChar);
par.Value = cinfo.SurName;
par = cmd.Parameters.Add("@customeraddress", SqlDbType.VarChar);
par.Value = cinfo.CustomerAddrees;
par = cmd.Parameters.Add("@customertelephone", SqlDbType.VarChar);
par.Value = cinfo.CustomerTelephone;
par = cmd.Parameters.Add("@customermobile", SqlDbType.VarChar);
par.Value = cinfo.CustomerMobile;
par = cmd.Parameters.Add("@customeremail", SqlDbType.VarChar);
par.Value = cinfo.CustomerEmail;
par = cmd.Parameters.Add("@addressproofid", SqlDbType.Int);
par.Value = cinfo.AddressProofId;
par = cmd.Parameters.Add("@addressproofname", SqlDbType.VarChar);
par.Value = cinfo.AddressProofName;
par = cmd.Parameters.Add("@idproofid", SqlDbType.Int);
par.Value = cinfo.IdProofId;
par = cmd.Parameters.Add("@idproofname", SqlDbType.VarChar);
par.Value = cinfo.IdProofName;
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

public DataTable ViewCustomerDetails(int customerid)
{
DataTable dt = new DataTable();
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter da = new SqlDataAdapter("CustomerDetailsView", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = da.SelectCommand.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = customerid;
da.Fill(dt);
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return dt;
}

public DataTable ViewCustomerDetailsByIdInAdminSide(int customerid)
{
DataTable dt = new DataTable();
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter da = new SqlDataAdapter("CustomerDetailsViewById", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = da.SelectCommand.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = customerid;
da.Fill(dt);
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return dt;
}
public long CustomerIdGenerate()
{
long newnumber = 0;
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}

SqlCommand cmd = new SqlCommand("CustomerIdGenerate", con);
cmd.CommandType = CommandType.StoredProcedure;

SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
newnumber = int.Parse(dr["Customer Id"].ToString());
}
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return newnumber;
}
public int CustomerCheck(int customerid)
{
int count = 0;
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("CustomerCheck", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = customerid;
count = int.Parse(cmd.ExecuteScalar().ToString());
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return count;
}


public int CustomerAddressProofNameCheck(string addressproofname)
{
int count = 0;
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("CustomerAddressProofNameCheck", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@addressproofname", SqlDbType.VarChar);
par.Value = addressproofname;
count = int.Parse(cmd.ExecuteScalar().ToString());
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return count;
}


public int CustomerIdProofNameCheck(string idproofname)
{
int count = 0;
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("CustomerIdProofNameCheck", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@idproofname", SqlDbType.VarChar);
par.Value = idproofname;
count = int.Parse(cmd.ExecuteScalar().ToString());
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return count;
}
public DataTable ViewAllCustomerDetails()
{
DataTable dt = new DataTable();
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter da = new SqlDataAdapter("CustomerDetailsViewAll", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.Fill(dt);
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return dt;
}
public DataTable CustomerDetailsPrint(int customerid)
{
DataTable dt = new DataTable();
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter adapter = new SqlDataAdapter("CustomerDetailsPrint", con);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = adapter.SelectCommand.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = customerid;
adapter.Fill(dt);
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return dt;
}
public void EditDetails(CustomerInfo cinfo)
{
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("EditCustomer", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = cinfo.CustomerId;
par = cmd.Parameters.Add("@firstname", SqlDbType.VarChar);
par.Value = cinfo.FirstName;
par = cmd.Parameters.Add("@surname", SqlDbType.VarChar);
par.Value = cinfo.SurName;
par = cmd.Parameters.Add("@customeraddress", SqlDbType.VarChar);
par.Value = cinfo.CustomerAddrees;
par = cmd.Parameters.Add("@customertelephone", SqlDbType.VarChar);
par.Value = cinfo.CustomerTelephone;
par = cmd.Parameters.Add("@customermobile", SqlDbType.VarChar);
par.Value = cinfo.CustomerMobile;
par = cmd.Parameters.Add("@customeremail", SqlDbType.VarChar);
par.Value = cinfo.CustomerEmail;
par = cmd.Parameters.Add("@addressproofid", SqlDbType.Int);
par.Value = cinfo.AddressProofId;
par = cmd.Parameters.Add("@addressproofname", SqlDbType.VarChar);
par.Value = cinfo.AddressProofName;
par = cmd.Parameters.Add("@idproofid", SqlDbType.Int);
par.Value = cinfo.IdProofId;
par = cmd.Parameters.Add("@idproofname", SqlDbType.VarChar);
par.Value = cinfo.IdProofName;
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public int CustomerCheckByName(string customername)
{
int count = 0;
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("CustomerCheckByName", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@customername", SqlDbType.VarChar);
par.Value = customername;
count = int.Parse(cmd.ExecuteScalar().ToString());
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return count;
}
public DataTable GetCustomerBySearch(string customername)
{
DataTable dt = new DataTable();
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter da = new SqlDataAdapter("GetCustomerBySearch", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = da.SelectCommand.Parameters.Add("@customername", SqlDbType.VarChar);
par.Value = customername;
da.Fill(dt);
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return dt;
}
public int CustomerCount()
{
int count = 0;
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}

SqlCommand cmd = new SqlCommand("CustomerCount", con);
cmd.CommandType = CommandType.StoredProcedure;

count = int.Parse(cmd.ExecuteScalar().ToString());
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return count;
}
public void CustomerDelete(int customerid)
{
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("CustomerDelete", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = cmd.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = customerid;

cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public DataTable TransactionViewByCustomerId(int customerid)
{
DataTable dt=new DataTable();
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter adapter=new SqlDataAdapter("TransactionViewByCustomerId", con);
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter par = new SqlParameter();
par = adapter.SelectCommand.Parameters.Add("@customerid", SqlDbType.Int);
par.Value = customerid;
adapter.Fill(dt);
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return dt;
}
}

Connection Class

using System.Data.SqlClient;

public class DBConnection
{
protected static SqlConnection con = new SqlConnection();
public DBConnection()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con = new SqlConnection(@"Data Source=STUDENTSERVER;Initial Catalog=DBEuroIndia;User ID=sa;password='cool';");
con.Open();
}
}

Thursday, March 18, 2010

Regular Expression For +ve integer

Regular Expression For +ve integer
..................................

^0*[1-9][0-9]*$