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

ASPX
<head runat="server">

    <style type="text/css">

     a img { border:none; }

    </style>

</head>

Microsoft SQL Version

Microsoft SQL Server Version list :
version Sql
515 Sql7
539 Sql2000
611 Sql2005sp1
612 Sql2005sp2
655 Sql2008sp1(dev10sp1)
sql2008sp2
Sql2008sp3
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

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

Display Long Date Formatted Regarding LocalCulture

ASPX
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

C#
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

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 : http://forums.asp.net/t/1820678.aspx/1?DataKey+get+a+gridview

Thursday, 3 January 2013

Redirect to UnAuthorized Page

Modify your global.asax like below :

VB
 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  
   sender.Response.Redirect("~/users/Unauthorized.aspx")  
 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.