Sunday, December 6, 2009

Getting the users login date and time in forms authentication

In this article we are going to see how to get the users login date and time. Go through these methods

Method 1: Through user ticket



Method 2: Membership Provider


Wednesday, November 18, 2009

Ajax is slow in Production server


We need to add these lines in Production Server

Monday, July 27, 2009

Check whether the user exist or not in webservice

In this article we are going to see if the user exist or not in webservices. There are many approach to do so.. we can create this by using XMLHTTP request or callback event handler and so on.. As you people know webservices are the most familiar approach to do so.. In this application we are going to check whether this user exist in asp.net builtin membership.. First you need to add some users in order to check this application..

Let us start by building this application..

Step1: open vs>File>New Website>give the name and click ok..

Step2: Right click on your website and click on webservices and give its name..

Step3: In the webservices uncomment this line
[System.Web.Script.Services.ScriptService]..
we need to uncomment this line in order to use ajax application on your page..

Step4:
Now give the webservice method name as usernameexist.. Write these lines of code


In this we are passing username.. As you might guess from the code that we are returning MembershipUser..

Step5:
Now open the Default.aspx page and add the ScriptManager on to the page and give the service reference to your web service.. write these lines of code..



In my case webservice name is WebService3.asmx and it will be differnt in your code..

Step6:
Now add the asp.net TextBox and the Html button on to your page.. And one more thing place the paragraph in order to store our message..



And double click on to the button..

Step7:
After double clicking We need to call the Webservice.. We need to write these lines of code



In this case first we are giving reference to Textbox by using a variable called text.. Then we need to call the webservice by adding the [classname].[webmethodname] and need to pass the parameters.. We are using onsuccess when that webservice got successed, onfailed for failure and the usercontext as "user exist".. We gave the reference to the paragraphid user by using a variable called span.. Now its a time to test your application..

I hope you like this Article..

Wednesday, June 17, 2009

backup the sql server programmatically

Give reference to your website
1)Microsoft.SqlServer.ConnectionInfo version 9
2)Microsoft.SqlServer.Smo version 9 and
3) Microsoft.SqlServer.sqlEnum version 9

Then write these lines of codes in page_load

Friday, May 1, 2009

Fileupload with virus scan in asp.net

In this article we are going to see how u can upload the file with virus scan..

Let us go through this step by step

Step1: create a new asp.net website..

Step2: open Default.aspx page.. In that drag and drop the FileUpload control,button and a label..



Step3: Add the Reference to your website naming log4net.dll and WRAVLib.dll.. you can download these from
http://www.wolfereiter.com/Downloads/wravlib/wravlib-1.1-strong-bin.zip..

Step4: Double click the Upload button and write in the code behind as follows


Step5: Run the application..

I hope you people like this application...

Thursday, April 30, 2009

Creating the Ajax Enabled Website using JQUERY

In this article,we will see how to create Ajax Enabled WCF service using Jquery..

The easiest way to create Ajax Enable WCF service is to use Ajax Enabled WCF service templete in visual studio..

Let us go through Example step by step...

Step1:Create an ASP.NET 3.5 Website

Step2:Right click the project>Add New Item>Choose Ajax Enabled WCF Service>name the service as Demo..


Step3:As you see the Demo.cs is added to App_Code.. When you open the Demo.cs by default it is created like this

[ServiceContract(Namespace = "wcfDemo")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]


Step4: Add the new method called getdata(int value)





Step5: Open Default.aspx page, In that add Scriptmanager from the toolbox and give its path..





Step6:Now add Html Button and Textbox inside the




Step7: Drag and Drop the Jquery script below



Step8: Now lets create the jquery script





Step9: As we used the datatype as json in jquery script so we need to add these line below the [OperationContract]





I hope you people like this application..

Monday, April 20, 2009

Setting the Maxlength in multiline textbox using javascript

This article is very useful when writing comments on your website.. There it will specify you to enter 100 character,200 characters something like that.. Lets Go through this article step by step..



step1:

Go to visual studio>add new website(C# or vb)..




step2:

Next is to add the textbox and label on your page.. set the TextMode of textbox to multiline,set the MaxLength to 100 and write the event as onKeyUp="javascript:charcount(this.id)"

After adding the page looks like this..



Step3:

Write the script tag below the head as




I hope you people like this article..

Tuesday, April 14, 2009

Prevent the User from selecting a Date Earlier than today

In this article i am using Calender extender to solve my problem easily..

I wil explain you step by step

step1:
open visual studio>click on File >New Website> choose your programming language (c# or vb)> Name the website>Choose your location..

step2:
Drag and drop the scriptmanger in your page..
the page looks like this



Step3:
Drag and drop the standard TextBox and Calender Extender.. Configure the calender Extender by giving the TargetControlID="TextBox1" and set OnClientDateSelectionChanged="checkdate".. we are using OnClientDateSelectionChanged to write the javascript to prevent the user from selecting a date earlier than today..

the page looks like this..




step5:
Now lets write the javascript






I hope you people like this application.Its easy to implement and very useful..

Monday, April 13, 2009

How to block a particular I.P. from accessing your site using HttpModule

This sample can be used to block a particular ipaddress from accessing resources on your website.We can retrieve information regarding client browser and client machine by making use of the Request object.Asp.Net uses a series of modules to get the work done for you.For a list of available modules in ASP.Net you can refer machine.config file present in %windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG folder.You can either use these modules or can create your custom module for the same.

HTTPMODULE:
An HttpModule is an assembly that implements the IHttpModule interface and handles events. ASP.NET includes a set of HttpModules that can be used by your application.. For example, the SessionStateModule is provided by ASP.NET to supply session state services to an application. Custom HttpModules can be created to respond to either ASP.NET events or user events..

The general process for writing an HttpModule is:

Implement the IHttpModule interface.
Handle the Init method and register for the events you need.
Handle the events.
Optionally implement the Dispose method if you have to do cleanup.
Register the module in Web.config.

Namespace for Httpmodule is: System.Web
Assembly:System.Web.dll
Let us go through the example step by step.. Step1: open visual studio> File > New > Website > chose ur language as c# as we are using in tour application> Select the location> Name the website Step2: Right click and add new item, select class and rename it as ipaddress.cs.. step3:




step 4:
Add these following lines in your code..

Type Your own ipaddress in ipadd to check the application...


step5: Adding Httpmodules in your Web.Config Type should be in namespace.classname format..




I hope you people like this application...

Wednesday, February 11, 2009

custom gridview sorting using asp.net






As you people know that Gridview is the most powerful functionality of .net. While sorting you can add images and text to your gridview column. If u use Gridview and Object datasource with custom paging then that will increase ur purpormance.. You can also do the same with sqldatasource,linq and entity..
Lets start developing our application..


step1: open visual studio.. click on file->new website->asp.net website-> give the name as customsorting.aspx close the programming language as c#..


step2:In the solution explorer right click the website and add new item.. click on dataset.xsd and name it as employee as i am building it for employee table..


Dataset looks like this..



you can also add multiple table just like linq and entities..
step3: next click on Default.aspx
drag and down gridview on default mode.. go to the design mode.. click on the smart tag click on add new datasouce.. next click on object.. give the connection to employee datatable.. click next and ok.. The code looks like this..







step 4: Now click on Default.cs.. for sorting we need to use Rowdatabound.. For that right click on the gridview go to property and click on rowdatabound.. you will see the code like this..
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
{
LinkButton btn = (LinkButton)cell.Controls[0];
if (btn.Text == GridView1.SortExpression)
{
if (GridView1.SortDirection == SortDirection.Ascending)
{
btn.Text += "desc";
}
else
{
btn.Text += "asc";
}
}
}
}
}

there different properties of gridviewrow such as


1)cells->represents the collection of table row being bound
2)rowtype->represents the type of row being bound..
3)row index->represents the type of index being bound..
4)rowstate->represents the type of state being bound..

step5: set the Default.aspx as startup page and click debug button or F5.. And see the program running..