Recent News

Email Validation from Codebehind

This is for check the email address from codebehind using regular expression.

if (System.Text.RegularExpressions.Regex.IsMatch(txtNewsletter.Text, "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{1,3})$") == false)
{
Page.RegisterStartupScript("GetType", "<script language='javascript'>alert('Please enter valid email address!')</script>'");
}

watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

Please have a look at the coding.......

<asp:TextBox runat="server" ID="txtSearch"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="twSearch" runat="server" TargetControlID="txtSearch"
WatermarkText="Search Products..." />
<span class="search_button">
<asp:ImageButton ID="butSearch1" runat="server" ImageAlign="Right" OnClick="butSearch1_Click"
Height="30px" />
</span>

Watermark Textbox using jquery

Here is the coding for Watermark inside a textbox. That is initially the message will show inside the textbox. Once you click on the textbox it will disappear. This is used by jquery.

CSS:

<style type="text/css" media="screen">
.water
{
font-family: Tahoma, Arial, sans-serif;
color: blue;
}
</style>

 
SCRIPT:
 
        <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
 
DESIGN:
  <div>


<h2>

Watermarked TextBox </h2>

<br />
<asp:TextBox ID="txtFirstName" class="water" Text="Enter First Name" ToolTip="Enter First Name" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtLastName" class="water" Text="Enter Last Name" ToolTip="Enter Last Name" runat="server"></asp:TextBox> <br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="vgNews" /></div>



 
Please give your comments if you need any clarification.... Also I will post watermark using ajax in the next post... Happy Coding!!!

If you need this Jquery please click here to download

Create XML file

Hi All,
   Here I have given the sample code to create a simple XML from .NET.
Please post your comments after review this....

string strfile = Server.MapPath("~/App_Data/simplexmlcreation.xml");
XmlTextWriter writexml = new XmlTextWriter(strfile, System.Text.Encoding.UTF8);
try
{
// write the top element and encode type
writexml.WriteStartDocument();
// write the starting element or root element
writexml.WriteStartElement("IPL");
// write first set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Chennai Super Kings");
writexml.WriteAttributeString("Points", "40");
writexml.WriteAttributeString("Captain", "Raina");
writexml.WriteString("CSK HAS MATHEW HAYDEN");
writexml.WriteEndElement();

//// write Second set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Kolkatta Knight Riders");
writexml.WriteAttributeString("Points", "45");
writexml.WriteAttributeString("Captain", "Saurav");
writexml.WriteString("KKR HAS Saurav Ganguly");
writexml.WriteEndElement();

//// write Third set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Royal Challangers Bangalore");
writexml.WriteAttributeString("Points", "55");
writexml.WriteAttributeString("Captain", "Kumble");
writexml.WriteString("KKR HAS Kalis");
writexml.WriteEndElement();

// Close the root Element
writexml.WriteEndElement();
//close the XML DOC
writexml.WriteEndDocument();
}

catch
{
throw;
}

finally
{
writexml.Close();
}



Thanks for reading my POST..... Keep Coding!!!!!!!

AUTHENTICATION and AUTHORIZATION

The web.config file has all of the configuration settings on an Application.
Authentication is the process of determining the authenticity of a user based on the user’s credentials.
Whenever a user logs in to an application, the user is first authenticated and then authorized.

1. Forms Authentication
2. Windows Authentication
3. Passport Authentication


You can set it in the web.config file as below,

or or

1. Forms Authentication:

This type of authentication is based on cookies. The username and password is stored in Database.This Forms authentication supports both Session and Cookies.
If the cookie isn't present, ASP.NET redirects the user to a web form you provide.
SYNTAX:


2. Windows Authentication:

This type of authentication is default one. Here a user can authenticated by their own windows account. So that this kind of Authentication is used only for Intranet not for web.
SYNTAX:


3. Passport Authnetication:
This passport authentication is the authentication service that uses the Microsoft's Passport Services. It allows the user to create a single sign in name and password to authenticated.

SYNTAX:


AUTHORIZATION:

It is the process of finding the accessibilty for a previously authenticated user.Authorization is only works with the Authenticated User/Person.

Download a Folder or File from .NET

Hi All,

  The below code is used to download the files from our .net coding...

#region downloadfile



public static bool downloadfile(string filename, string path)


{


try


{


FileStream sourceFile;


HttpResponse response = HttpContext.Current.Response;


response.ContentType = "application/x-rar-compressed";


response.AddHeader("content-disposition", "attachment; filename=" + filename + Path.GetExtension(path).ToString());


sourceFile = new FileStream(path, FileMode.Open);


long FileSize;


FileSize = sourceFile.Length;


byte[] getContent = new byte[(int)FileSize];


sourceFile.Read(getContent, 0, (int)sourceFile.Length);


sourceFile.Close();


sourceFile.Dispose();


response.BinaryWrite(getContent);


response.Flush();


response.Clear();


response.Close();


return true;


}


catch (Exception ex)


{


return false;


}


}


#endregion
 
 
 Happy Coding!!!!!!!

SQL JOIN QUERIES

JOIN QUERIES:

INNER JOIN:

select col1,col2 from tablename1 as aliasname1 inner join tablename2 as aliasname2 on aliasname1.field1 = aliasname2.field1

eg: here I have given the detaild explanation below,

to use the join queries we need atleast two tables. We need a common field in both tables. otherwise we can say like, we need a forign key table and primary key table.
Let us take a tbl_user table has primary key of userid. and let us take another table tbl_Item has the foregn key of same userid which has refered by tbl_Item.
If we need to get item which has been uploaded by a particular user. for this scenario we can use below query,

select I.itemid,I.itemname,U.username,U.Firstname,U.Lastname from tbl_User U INNER JOIN tbl_Item I on I.userid = U.userid

This inner join query is used to get the records or data present in the both column refered by a common column or field.
There are many other joins like left outer join, right outer join.
These type of joins is used to get the whole values including the common values.
Let me explain with a simple scinario.

Let us take we are showing a item listing page. In this page we are showing all the items with item name, item description along with total sales count of the particular item.
Here you may not use INNER JOIN. Since if you are using inner join we can get only the details which the item sales more than one time.
So the net result is we can not showing the items which has 0 sales count. For this you can use the Left outer join or Right Outer Join instead of INNER JOIN.
So it will give the results including the 0 sales count.

GET DATE:

If you need to get the currentdate then you can use the following query,

select getdate() as DATETIME

DATEADD:
If you need to get the past 6 Months record you can use the following,

SELECT * FROM tbl_User WHERE createddate > DATEADD(m, -6, current_timestamp);

SORTING:

Keyword: desc ----> It will give the records in DESCENDING

select ItemID, UserID, Name,Description from tbl_item where isfeatured = 1 order by CreatedDate DESC

Keyword: ASC ----> It will give the records in ASCENDING

select ItemID, UserID, Name,Description from tbl_item where isfeatured = 1 order by CreatedDate ASC


LIKE QUERY:

SELECT * FROM tbl_Item WHERE itemname like @sql+'%';

or

SELECT * FROM tbl_Item WHERE itemname like 'saravan%';

In this Like condition we should use LIKE and %. That is these two are the main key words.
From the above Query if we are using % at last with the parameter, then it will give all the values which starts with the parameter.
If you see the second example you can get the clear idea about this.

SELECT * FROM tbl_Item WHERE itemname like '%'+@sql+'%';

Here you can get the values which has contain the word @sql or parameter as an Output.

You can also show the records which has not start with some particular letters.

eg: SELECT * FROM tbl_Item WHERE itemname not like 'H%';

also you can use the query to get the values with some exclude data like,

NOT EQUAL TO:(<>)

SELECT Company, Country FROM Customers WHERE Country <> 'USA'

Here you can get the company name and country name from customers except USA.

Simple Basic Queries

In this post I have explained some simple queries with an explanation. This may help ful for beginners.

SELECT QUERY:

select fieldname(s) from tablename

eg: select itemid,itemname,itemdesc from tbl_Item

UPDATE QUERY:

update tablename set col1=@param1,col2=@param2

eg: update tbl_Item set itemname = @itemname,itemdesc = @desc where itemid = @itemid

Here you can use the where condition to update a particular column in the table. If you need to update the values without any condition then you can have the same query but with out the where condition. Please see below for your reference,

eg: update tbl_Item set itemname = @itemname,itemdesc = @desc

Note: @itemname,@desc are the parameter.

DELETE QUERY:

delete from tablename

eg: delete from tbl_Item where itemid = @itemid

here you can delete the particular rows of a table. Thats is you can delete rows or data for particular itemid. But you can delete whole table with out anycondition you can use the same with out where condition.

TRUNCATE TABLE:

truncate table tablename

eg: truncate table tbl_Item

DIFF BETWEEN DELETE AND TRUNCATE:


Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command. Simply said it will reset the table with the new one. But it wont affect the structure of the table.

INSERT QUERY:

insert into tablename(col1,col2,col3) values(@param1,@param2,@param3)

eg:  insert into tbl_Item(itemname,desc) values(@itemname,@desc)

Followers

Top Commentators

Recent Comments | Recent Posts


bottom