.Net All About

.Net All About

How to Create Meta Tags Programmatically in ASP.NET 2.0

If you have been Developing Web, you may be familiar with the meta tags in an HTML page. The meta tags are used to provides keywords etc in an HTML page.

Now in ASP.NET 2.0, you can add these meta tags programmatically. The HtmlMeta class provides programmatic access to the HTML element on the server. The HTML element is a container for data about the rendered page, but not page content itself.

The Name property of HtmlMeta provides the property name and the Content property is used to specify the property value. The Scheme property to specify additional information to user agents on how to interpret the metadata property and the HttpEquiv property in place of the Name property when the resulting metadata property will be retrieved using HTTP.

The following code shows how to add meta tags to a page programmatically.

HtmlMeta metaTag = new HtmlMeta();
metaTag.Name = “Keywords”;
metaTag.Content = “Yogesh”;
this.Header.Controls.Add(metaTag);

Add the above created method to Load event of the Page. Now The Result can be seen by viewing dynamically cretaed source of the Page.

Similarly, you can add multiple meta tags to the header of the Page.

You can also add sechema to the Contact.

// Render:
meta = new HtmlMeta();
meta.Name = “date”;
meta.Content = DateTime.Now.ToString(“yyyy-MM-dd”);
meta.Scheme = “YYYY-MM-DD”;
this.Header.Controls.Add(meta);

July 24, 2009 Posted by | Asp.net | | 3 Comments

Split value function SQL SERVER

Create FUNCTION [dbo].[SplitValues](@Str varchar(max),@Deliminator varchar(100))
returns @t table (numberval numeric(25), stringval varchar(100), DateVal datetime)
as
begin

declare @i int;
declare @c varchar(100);

–set @Str = @Str + ‘,’
set @Str = @Str + @Deliminator
set @i = 1;
set @c = ”;

while @i <= len(@Str)
begin
–if substring(@Str,@i,1) = ','
if substring(@Str,@i,1) = @Deliminator
begin
insert into @t
values (CASE WHEN isnumeric(@c)=1 THEN @c else Null END,
rtrim(ltrim(@c)),
CASE WHEN isdate(@c)=1 then @c else Null END)
set @c = ''
end
else
set @c = @c + substring(@Str,@i,1)
set @i = @i +1
end
return
end

—————-
to call this function,use following…

select * from dbo.SplitValues('1,2,3,4,5',',')

————-
this will return following results…

items
——–
1
2
3
4
5

July 14, 2009 Posted by | SQL Server 2005 | | Leave a Comment

AutoCompleteExtender Control in the ASP.NET AJAX Toolkit

The AutoCompleteExtender Control in the ASP.NET AJAX Toolkit is an awesome way to offer suggestions to users in your ASP.NET Web Applications. It is also very easy to use.

Create an ASP.NET AJAX Website and toss a TextBox and the AutoCompleteExtender Control on the page.

Fill out the details of the control to specify the appropriate ServicePath and ServiceMethod of the web service that the AutoCompleteExtender Control will call. In this case I have a web service, called MyAutocompleteService, with a web method, called GetSuggestions. The control will start offering me suggestions once the first character is typed into the TextBox and ask for up

The GetSuggestions WebMethod on the WebService echos back what was typed in an just appends up to 12 characters ( A- L ) to the text typed in. Note the addition of the [ScriptService] Attribute to use the WebService with AJAX.

[WebMethod]
public string[] GetCountriesList(string prefixText)
{
DataSet dtst = new DataSet();
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string strSql = “SELECT CountryName FROM Tbl_Countries WHERE CountryName LIKE ‘”+ prefixText+”%’ “;
SqlCommand sqlComd = new SqlCommand(strSql,sqlCon);
sqlCon.Open();
SqlDataAdapter sqlAdpt = new SqlDataAdapter();
sqlAdpt.SelectCommand = sqlComd;
sqlAdpt.Fill(dtst);
string[] cntName = new string[dtst.Tables[0].Rows.Count];
int i = 0;
try
{
foreach (DataRow rdr in dtst.Tables[0].Rows)
{
cntName.SetValue(rdr["CountryName"].ToString(), i);
i++;
}
}
catch { }
finally
{
sqlCon.Close();
}
return cntName;
}

test

July 7, 2009 Posted by | Asp.net | | 1 Comment

Fetch Numer/AlphaNumeric value from Varchar table’s Field In SQL SERVER

Following function keeps only numeric characters in string and removes all the other character from the string. This is very handy function.

Create FUNCTION dbo.GetNumberFromVarcharField
(
@string VARCHAR(max) — varchar field value
)
RETURNS VARCHAR(max)
AS
BEGIN

DECLARE @IncorrectCharLoc SMALLINT
SET @IncorrectCharLoc = PATINDEX(‘%[^0-9]%’, @string)
WHILE @IncorrectCharLoc > 0
BEGIN
SET @string = STUFF(@string, @IncorrectCharLoc, 1, ”)
SET @IncorrectCharLoc = PATINDEX(‘%[^0-9]%’, @string)
END
SET @string = @string
RETURN @string
END

— test
SELECT dbo.GetNumberFromVarcharField(‘sadas????ASDa######10′)

Following function keeps only Alphanumeric characters in string and removes all the other character from the string. This is very handy function too.

CREATE FUNCTION dbo.GetAlphaNumericString
(
@string VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @IncorrectCharLoc SMALLINT
SET @IncorrectCharLoc = PATINDEX(‘%[^0-9A-Za-z]%’, @string)
WHILE @IncorrectCharLoc > 0
BEGIN
SET @string = STUFF(@string, @IncorrectCharLoc, 1, ”)
SET @IncorrectCharLoc = PATINDEX(‘%[^0-9A-Za-z]%’, @string)
END
SET @string = @string
RETURN @string
END
GO

– Test
SELECT dbo.GetAlphaNumericString(‘ABC”_I+{D[]}4|:e;””5,/?6′)

July 3, 2009 Posted by | SQL Server 2005 | | Leave a Comment

True Random Number/String Generator

int maxSize = 8;
char[] chars = new char[62];
string a;
a = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890″;
chars = a.ToCharArray();
int size = maxSize;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data);
size = maxSize;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size);
foreach (byte b in data)
{
result.Append(chars[b % (chars.Length - 1)]);
}

strCode = (result.ToString()).ToUpper();

bool flag = false;
for (int i = 0; i < strCode.Length; i++)
{
if (char.IsDigit(strCode, i))
{
flag = true;
}
}
if (flag == false)
{
GetRandomUniqueAlphaNumericCode();
}
return strCode; // this is class static field
}

this will generate random and unique alphanumeric string.

July 1, 2009 Posted by | Asp.net | | 4 Comments

Forums for Microsoft .NET developers

Hi begginers to Microsoft.NET world, here a list of forums and educational sites where you can post your queries and get ur answers from professionals. this may help you to increase your knowledge and also help if u stuck with some issues…become a regular member(its free) so that source code access is easy ….and also contibute wen u have enough greymatter to solve complex issues of .NET. Comment on this post and add more forums which i might have missed …..

www.eggheadcafe.com

www.c-sharpcorner.com

www.vbdotnetheaven.com

www.dotnetheaven.com

forums.asp.net

www.codeproject.com

www.eggheadcafe.com

www.4guysfromrolla.com

www.aspalliance.com

www.devasp.net

DotNetCommunity

www.w3schools.com

July 1, 2009 Posted by | Asp.net | | 1 Comment

How to detect browser using JavaScript

var isIE = false;
var isFF = false;
var isOP = false;
var isSafari = false;

function DetectBrowser()
{
var val = navigator.userAgent.toLowerCase();
if(val.indexOf(“firefox”) > -1)
{
isFF = true;
}
else if(val.indexOf(“opera”) > -1)
{
isOP = true;
}
else if(val.indexOf(“msie”) > -1)
{
isIE = true;
}
else if(val.indexOf(“safari”) > -1)
{
isIE = true;
}
}

July 1, 2009 Posted by | Asp.net | | 4 Comments

   

Follow

Get every new post delivered to your Inbox.