Wednesday, 10 July 2013

Delete Confirmation Box

<asp:LinkButton ID="lnkDelete" runat="server" 
CommandName="Delete" Text="Delete"
OnClientClick = "return confirm('Are you sure?')" />

Tuesday, 12 March 2013

Hide HyperLink if Database cell is NULL

Visible ='<%# Eval("a") == System.DbNull.Value ? False : True %>'

Wednesday, 6 March 2013

Upload File in VB

Dim spath As String = Server.MapPath("~/foldername/")
Dim sfile As String = FileUpload1.FileName
Dim sfullpath As String = spath & "\" & sfile

Catch ex As Exception
  Label1.Text = "Failed. " & ex.Message
End Try

Tuesday, 5 March 2013

errors : The name ... does not exist in the current

Make sure inherits and class same name

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="office.aspx.cs" Inherits="TEST_office" %>

public partial class TEST_office : System.Web.UI.Page

Thursday, 7 February 2013

SQL : Get Date Only


SQL 2008

Friday, 1 February 2013

IIS 7 Blank Image Problem

Fisrttime when using IIS 7 in Windows 2008 Server i got problem. I can not display all image. After googling I get the solution. The problem is static content not checked yet.

Thursday, 31 January 2013

Get GridViewRow from Autopostback control event

Sometime we have checkbox control or other control inside gridview.
We need to do when checkbox clicked then some action affected to that row, for example getting datakey, rowindex or getting cell value.

      <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" 
        oncheckedchanged="CheckBox1_CheckedChanged" />

This sample code is getting gridviewrow from checkbox checked changed event then displaying value from another cell to a label.

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
  GridViewRow gvrow = ((Control)sender).Parent.Parent as GridViewRow;
  Label1.Text = gvrow.Cells[2].Text;

Using Naming Container

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        GridViewRow row=(GridViewRow)(((CheckBox)sender).NamingContainer);


Wednesday, 30 January 2013

Export Datatable

public static void ExportToSpreadsheet(DataTable table, string name)
   HttpContext context = HttpContext.Current;
   foreach (DataColumn column in table.Columns)
    context.Response.Write(column.ColumnName + ";");
   foreach (DataRow row in table.Rows)
    for (int i = 0; i < table.Columns.Count; i++)
     context.Response.Write(row[i].ToString().Replace(";", string.Empty) + ";");
   context.Response.ContentType = "text/csv";
   context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name + ".csv");

JavaScript : Auto Maximize Window Script

<script language="JavaScript1.2">

* Auto Maximize Window Script- © Dynamic Drive (
* This notice must stay intact for use
* Visit for this script and 100's more.

if (document.all) {
else if (document.layers||document.getElementById) {
if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;

Source :

Monday, 28 January 2013

Show Error Detail for 500 internal server error

<customErrors mode="off"/>

        <httpErrors errorMode="Detailed" /> 
        <asp scriptErrorSentToBrowser="true"/>    
        <remove value="default.aspx" /> 
        <add value="default.aspx" /> 

Sunday, 27 January 2013

CSS:Remove asp:Hyperlink blue border

When using asp Hyperlink with ImageUrl value. Usualy the image has blue border in browser. You can remove the blue border by CSS code below

<head runat="server">

    <style type="text/css">

     a img { border:none; }



Microsoft SQL Version

Microsoft SQL Server Version list :
version Sql
515 Sql7
539 Sql2000
611 Sql2005sp1
612 Sql2005sp2
655 Sql2008sp1(dev10sp1)
661 Sql2008r2
705 Sql2012(RC0)
706 Sql2012(RC1/RTM)

Saturday, 12 January 2013

Refresh page periodicaly

If you want to refresh a page periodicaly use META tag like below

<meta http-equiv="Refresh" content="300" />

Display Long Date Formatted Regarding LocalCulture

using System.Globalization;
using System.Threading;

private void Page_Load(object sender, System.EventArgs e)
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0].ToString());
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(Request.UserLanguages[0].ToString());

    lblToday.Text = Today;

    lblMessage.Text = "Culture Info Display Name " + Thread.CurrentThread.CurrentCulture.DisplayName;

Adding Double Quote to a string using c#

This sample is how to add "sample" (double quote is included) to a string

string mystring = @""sample""

DataKey get a gridview

Question :

Using VS2010, C #, AspNet4
I principal.aspx page, contains a GridView1 with fields Id and Name, Id is the DataKey.
Select any line on the grid and open a new page called editar.aspx.
How using a button, I get the Id of the selected row to edit the page editar.aspx
Answer :
You can use hyperlinkfield to open editor.aspx

<hyperlinkfield Text="Edit Data" DataNavigateUrlFields="ID"
DataNavigateUrlFormatString="editar.aspx?id={0} />

in editar.aspx use querystring("id") to filter the data.
It's not using selected row and datakeyname. Hyperlink only

source :

Thursday, 3 January 2013

Redirect to UnAuthorized Page

Modify your global.asax like below :

 Public Sub Application_AuthorizeRequest(ByVal sender As Object, ByVal e As EventArgs)  
 If (sender.Request.Path.ToUpper().EndsWith("LOGIN.ASPX") And sender.Request.IsAuthenticated) Then  
 End If  
 End Sub 

When you already loged-in and want to access unauthorized page, usualy the page redirect to login.aspx again without any message that you rectricted.