Friday, April 15, 2011

How to create Website Page in Asp.net using visual studio 2008, 2010

        First of all you have to install visual studio. The Visual Studio Express edition is freely available on the Microsoft Visual Studio Site. You need to install the web developer only, if you plan to develop website only.

Step 1: open the visual studio

Step 2:  Click on File => New => Website.

Step 3: From installed template choose the language( c# or vb) and choose the web location as File System. Then give the Website Name and click ok.

Step 4: A default.aspx and about.aspx page will be created in the solution explorer automatically.

Step 5: Under the Solution Explore side bar Right click on the website name and Select Add New Item.

Step 6: A new window will open with all available options. Select Web Form , then provide the name below and click on add.

Step 7: In the main window there are three options " Design, Split And Source" Now if you want to use drag and drop the buttons or components on the web page, then select Design otherwise choose source to add buttons and styles manually.

Saturday, March 19, 2011

Master Pages In ASP.Net

                With Master pages in ASP.Net, we can use visual inheritance in our ASP.NET application. Since most of the ASP.NET applications have similar structure or design throughout the whole pages, so it is logical to build a page design (template) once and use it throughout the application.

 For example:  


Validating A User In Code Using C# and VB.net

C#

if (Membership.ValidateUser (UserName.Text, Password.Text))
{
  //access code will be written here.
}


VB

if (Membership..ValidateUser (Username.Text, Password.Text))
{
//allow access code will be written here.

Thursday, March 3, 2011

How to Connect to an Access Database Using the Access DataSource Control in Visual Studio


To use the AccessDataSource control to connect to an Access database

1.     Open the page from which you want to connect to an Access database.

2.        Switch to Design view.

3.        From the Data group on the Toolbox, drag an AccessDataSource  onto your page.

4.        If the Smart Tag panel is not displayed, right-click the control and click Show Smart Tag.

5.        In the AccessDataSource Tasks list, click Configure Data Source.
The Configure Data Source wizard is displayed.

6.         In the Choose a Database pane, type or select the path to your Microsoft Access database, which will have .mdb as the file name extension..

       (It is recommend that you store your Access database in the Web site's App_Data folder to ensure that the Web server will not return the .mdb file in response to a Web request

7:Click Next.

8: In the Configure the Select Statement pane, if you want to use the wizard to create a SQL query, click Specify columns from a table or view and use the options in the pane to configure your query.   (To have the wizard generate Insert, Update, and Delete statements based on the Select statement you are creating, clickAdvanced.

9:    If you want to use the query builder or write your Select query, click Specify a custom SQL statement or stored procedure, clickNext, and then write your SQL statement. Click the UPDATE, INSERT, or DELETE tabs to create update statements.  

10: Click Next.       

11: In the Test Query pane, click Test Query to determine whether the query returns the results you want.
       Click Finish.



How To Write Connection String in ASP.Net


Placing File in Web.config file.

       The connection string provides the information that a provider needs to communicate with a particular database. We can store a connection string in the Web.config file and reference the configuration entry in a data source control.

Depending upon the provider, a connection string usually supplies the server or location of the database server, the particular database to use, and authentication information.

We should place connection strings in the Web.config file. Within the <configuration> element, you have to create a child element named <connectionStrings> and then place your connection strings there.


<connectionStrings>
  <add name="connect1"
   connectionString=" Server=YourDataServer;Integrated Security=SSPI;Database=mydata.mdf;"
   providerName="System.Data.SqlClient" />
</connectionStrings>


By Writing Code in the .CS page file under the page load event or under the button_click event.

for Access:
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database/RMS.mdb"));


For SqlServer:
SqlConnection con = new SqlConnection("Data Source=74.55.199.22 ;Network Library=DBMSSOCN;Initial Catalog=student;User ID=shaan;Password=shaan;")

Friday, January 14, 2011

Page.IsPostBack Property

The Page_Load( ) every time the page is loaded. If Page.IsPostBack property is set to false the page will load for the first time and if it is set to true it will be posted back to the server every time an action is performed on the  page.

Monday, December 20, 2010

Events And Event Handling

Asp.net object has an event associated with it. These events need an event handler. The name assigned to an event in a tag is the name of the event handler. So the code-

OnTextChanged="ChangeXYZ"

names the C# function that handles the event ChangeXYZ. In the C# portion of the visual studio application, we will see the method that handles the OnTextChanged event as

protected void ChangeXYZ(object sender, EventsArgs e)
{
//statements
}