Feb 26, 2010

Asp.Net Remoting

What are possible implementations of distributed applications in .NET?
.NET Remoting and ASP.NET Web Services. If we taLk about the Framework CLass Library, noteworthy cLasses are in System.Runtime.Remoting and System.Web.Services.

When would you use .NET Remoting and when Web services?
Use remoting for more efficient exchange of information when you controL both ends of the appLication. Use Web services for open-protocoL-based information exchange when you are just a cLient or a server with the other end beLonging to someone eLse.

What’s a proxy of the server ob3ect in .NET Remoting?
ItIs a fake copy of the server object that resides on the cLient side and behaves as if it was the server. It handLes the communication between reaL server object and the cLient object. This process is aLso known as marshaLing.

What are remotable ob3ects in .NET Remoting?
RemotabLe objects are the objects that can be marshaLed across the appLication domains. You can marshaL by vaLue, where a deep copy of the object is created and then passed to the receiver. You can aLso marshaL by reference, where just a reference to an existing object is passed.

What are channels in .NET Remoting?

ChanneLs represent the objects that transfer the other seriaLized objects from one appLication domain to another and from one computer to another, as weLL as one process to another on the same box. A channeL must exist before an object can be transferred.

What security measures exist for .NET Remoting in System.Runtime.Remoting?

None. Security shouLd be taken care of at the appLication LeveL. Cryptography and other security techniques can be appLied at appLication or server LeveL.

What is a formatter?

A formatter is an object that is responsibLe for encoding and seriaLizing data into messages on one end, and deseriaLizing and decoding messages into data on the other end.

Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters, what are the trade-offs?
Binary over TCP is the most effiecient, SOAP over HTTP is the most interoperabLe.

What’s SingleCall activation mode used for?

If the server object is instantiated for responding to just one singLe request, the request shouLd be made in SingLeCaLL mode.

What’s Singleton activation mode?

A singLe object is instantiated regardLess of the number of cLients accessing it. Lifetime of this object is determined by Lifetime Lease.

How do you define the lease of the ob3ect?

By impLementing ILease interface when writing the cLass code.

Can you configure a .NET Remoting ob3ect via XML file?

Yes, via machine.config and appLication LeveL .config fiLe (or web.config in ASP.NET).

AppLication-LeveL XML settings take precedence over machine.config.

How can you automatically generate interface for the remotable ob3ect in .NET with

Microsoft tools?

Use the Soapsuds tooL.

Main Link For Dot Net

**** .net all effects of trail in live:




***This is a link to conevert to C#.net TO VB.net
http://www.developerfusion.com/tools/convert/csharp-to-vb/

All java Scripts link
http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

***ajax.net action page:
Site:
http://www.dofactory.com/Framework/Framework.aspx

http://www.dofactory.com/Ajax/Source/AjaxSource.aspx?id=AjaxMessageText&file=

Ajax sites download:

http://asp.net/ajax/downloads/

http://blogs.msdn.com/kirti/


Ajax toolkit properties all:
http://asp.net/AJAX/AjaxControlToolkit/Samples/Rating/Rating.aspx



.net material 3tire,web services:
http://www.c-sharpcorner.com/UploadFile/ashok_kp/IntroductionToWebServicesT11252005045531AM/IntroductionToWebServicesT.aspx

.net controls site:

http://demos.devexpress.com/ASPxperienceDemos/PopupControl/Features.aspx

Java scripts:

http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

a great software , update to 2.51 versiom

http://effectmatrix.com/Youtube_video_download_tool/index.htm


A_Programmers_Introduction_to_Visual_Basic.NET.pdf

http://rapidshare.com/files/91385783/A_Programmers_Introduction_to_Visual_Basic.NET.pdf

Applied_Microsoft.NET_Framework_Programming.pdf

http://rapidshare.com/files/91385956/Applied_Microsoft.NET_Framework_Programming.pdf

Apress.dot.NET.

2.0.Interoperability.Recipes.A.Problem.Solution.Approach.Mar.2006.pdf

http://rapidshare.com/files/91386689/Apress.dot.NET.2.0.Interoperability.Recipes.A.Problem.Solution.Approach.Mar.2006.pdf
Apress.Foundations.of.Object.Oriented.Programming.Using.dot.NET.
2.0.Patterns.Oct.2005.pdf

http://rapidshare.com/files/91386979/Apress.Foundations.of.Object.Oriented.Programming.Using.dot.NET.2.0.Patterns.Oct.2005.pdf


ASP.NET_2.0_Unleashed.chm

http://rapidshare.com/files/91388239/ASP.NET_2.0_Unleashed.chm


ASP.NET_for_Developers.pdf

http://rapidshare.com/files/91389149/ASP.NET_for_Developers.pdf


Beginning_Ajax_with_ASP.NET.pdf

http://rapidshare.com/files/91389410/Beginning_Ajax_with_ASP.NET.pdf


Beginning_ASP_.NET_3.5_in_C__2008_Second_Edition.pdf

http://rapidshare.com/files/91390785/Beginning_ASP_.NET_3.5_in_C__2008_Second_Edition.pdf


Beginning_ASP.NET_2.0__Wrox2006__by_Tantanoid.pdf

http://rapidshare.com/files/91391107/Beginning_ASP.NET_2.0__Wrox2006__by_Tantanoid.pdf


Beginning_ASP.NET_3.5_in_C__2008_Second_Edition.pdf

http://rapidshare.com/files/91392565/Beginning_ASP.NET_3.5_in_C__2008_Second_Edition.pdf



Microsoft.Press.Application.Interoperability.Microsoft.Dot.NET.and.J2EE.Dot.Patterns._.Practices.eBo

http://rapidshare.com/files/91392684/Microsoft.Press.Application.Interoperability.Microsoft.Dot.NET.and.J2EE.Dot.Patterns._.Practices.eBo


Pro_.NET_2.0_Code_and_Design_Standards_in_C_.pdf

http://rapidshare.com/files/91393152/Pro_.NET_2.0_Code_and_Design_Standards_in_C_.pdf


Pro_.NET_2.0_Windows_Forms_and_Custom_Controls_in_C_.pdf

http://rapidshare.com/files/91394280/Pro_.NET_2.0_Windows_Forms_and_Custom_Controls_in_C_.pdf


Pro_ADO.NET_2.0.pdf

http://rapidshare.com/files/91394597/Pro_ADO.NET_2.0.pdf


Pro_ASP.NET_2.0_in_C__2005.pdf

http://rapidshare.com/files/91395501/Pro_ASP.NET_2.0_in_C__2005.pdf


Pro_Scalable_.NET_2.0_Application_Designs.pdf

http://rapidshare.com/files/91397861/Pro_Scalable_.NET_2.0_Application_Designs.pdf


Professional_.NET_Framework_2.0.chm

http://rapidshare.com/files/91398772/Professional_.NET_Framework_2.0.chm



Professional_ADO.NET_2_Programming_with_SQL_Server_2005_Oracle_and_MySQL.pdf


http://rapidshare.com/files/91399412/Professional_ADO.NET_2_Programming_with_SQL_Server_2005_Oracle_and_MySQL.pdf


Professional_Web_Parts_and_Custom_Controls_with_ASP.NET_2.0.pdf

http://rapidshare.com/files/91400468/Professional_Web_Parts_and_Custom_Controls_with_ASP.NET_2.0.pdf


SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.001

http://rapidshare.com/files/91402148/SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.001


SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.002

http://rapidshare.com/files/91403458/SAMS_ASP.NET_2.0_Unleashed_SourceCode.zip.002


Teach_Yourself_ASP.NET_2.0_in_24_Hours.chm

http://rapidshare.com/files/91404750/Teach_Yourself_ASP.NET_2.0_in_24_Hours.chm
MCTS certification info

ADO.NET QUESTION ANSWER

What is a dataset? 
A dataset is the local repository of the data used to store the tables and disconnected record set. When using disconnected architecture, all the updates are made locally to dataset and then the updates are performed to the database as a batch.
 

What is a data adapter?
A data adapter is the component that exists between the local repository (dataset) and the physical database. It contains the four different commands (SELECT, INSERT, UPDATE and DELETE). It uses these commands to fetch the data from the DB and fill into the dataset and to perform updates done in the dataset to the physical database. It is the data adapter that is responsible for opening and closing the database connection and communicates with the dataset.

 

What is a database connection?
A database connection represents a communication channel between you application and database management system (DBMS). The application uses this connection to pass the commands and queries to the database and obtain the results of the operations from the database.
 

What is a database command?
A database command specifies which particular action you want to perform to the database. The commands are in the form of SQL (Structured Query Language). There are four basic SQL statements that can be passed to the database.
SQL SELECT Statement
This query is used to select certain columns of certain records from a database table.
SELECT * from emp// sql steaments
selects all the fields of all the records from the table name ‘emp’
SELECT empno, ename from emp
selects the fields empno and ename of all records from the table name ‘emp’
SELECT * from emp where empno <>
selects all those records from the table name ‘emp’ that have the value of the field empno less than 100
SELECT * from article, author where article.authorId = author.authorId
selects all those records from the table name ‘article’ and ‘author’ that have same value of the field authorId
SQL INSERT StatementThis query is used to insert a record to a database table.
INSERT INTO emp(empno, ename) values(101, ‘John Guttag’)
inserts a record to emp table and set its empno field to 101 and its ename field to ‘John Guttag’
SQL UPDATE Statement
This query is used to edit an already existing record in a database table.
UPDATE emp SET ename =‘Eric Gamma’ WHERE empno = 101
updates the record whose empno field is 101 by setting its ename field to ‘Eric Gamma’
SQL DELETE Statement
This query is used to delete the existing record(s) from the database table
DELETE FROM emp WHERE empno = 101deletes the record whose empno field is 101 from the emp table
 

What is a data reader?
The data reader is a component that reads the data from the database management system and provides it to the application. The data reader works in the connected manner; it reads a record from the DB, pass it to the application, then reads another and so on.
How do 

different components of ADO.Net interact with each other in disconnected architecture?The Data Adapter contains in it the Command and Connection object. It uses the connection object to connect to the database, execute the containing command, fetch the result and update the DataSet.

What does it mean by Dot Net Framework Data Provider?
Dot Net Framework Data Provider is a set of classes that establishes the database communication between an application and the database management system based on the standards of ADO.Net framework. Different data providers provide specialized and optimized connectivity to particular database management system or to a particular class of DBMS. For example, the MS SQL Server data provider provides the optimized connectivity between dot net application and MS SQL Server DBMS while the OLEDB data provider provides the uniform connectivity between dot net application and the OLEDB databases.






What is ADO.Net?
Most of the today’s applications need to interact with database systems to persist, edit or view data. In .Net data access service is provided through ADO.Net (ActiveX Data Object in Dot Net) components. ADO.Net is an object oriented framework that allows you to interact with database systems. We usually interact with database systems through SQL queries or stored procedures. ADO.Net encapsulates our queries and commands to provide a uniform access to various database management systems.
ADO.Net is a successor of ADO (ActiveX Data Object). The prime features of ADO.Net are its disconnected data access architecture and XML integration.
 
What does it mean by disconnected data access architecture of ADO.Net?
ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the database system and then interact with it through SQL queries using the connection. The application stays connected to the DB system even when it is not using DB services. This commonly wastes the valuable and expensive database resource as most of the time applications only query and view the persistent data. ADO.Net solves this problem by managing a local buffer of persistent data called data set. Your application automatically connects to the database server when it needs to pass some query and then disconnects immediately after getting the result back and storing it in dataset. This design of ADO.Net is called disconnected data architecture and is very much similar to the connection less services of http over the internet. It should be noted that ADO.Net also provides the connection oriented traditional data access services.

 
What does it mean by disconnected data access architecture of ADO.Net?ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the database system and then interact with it through SQL queries using the connection. The application stays connected to the DB system even when it is not using DB services. This commonly wastes the valuable and expensive database resource as most of the time applications only query and view the persistent data. ADO.Net solves this problem by managing a local buffer of persistent data called data set. Your application automatically connects to the database server when it needs to pass some query and then disconnects immediately after getting the result back and storing it in dataset. This design of ADO.Net is called disconnected data architecture and is very much similar to the connection less services of http over the internet. It should be noted that ADO.Net also provides the connection oriented traditional data access services.
 
What does it mean by connected data access architecture of ADO.Net?
In the connected environment, it is your responsibility to open and close the database connection. You first establish the database connection, perform the interested operations to the database and when you are done, close the database connection. All the changes are done directly to the database and no local (memory) buffer is maintained.
 
What's the difference between accessing data with dataset or data reader?
The dataset is generally used when you like to employ the disconnected architecture of the ADO.Net. It reads the data into the local memory buffer and perform the data operations (update, insert, delete) locally to this buffer.
The data reader, on the other hand, is directly connected to the database management system. It passes all the queries to the database management system, which executes them and returns the result back to the application.
Since no memory buffer is maintained by the data reader, it takes up fewer resources and performs more efficiently with small number of data operations. The dataset, on the other hand is more efficient when large number of updates are to be made to the database. All the updates are done in the local memory and are updated to the database in a batch. Since database connection remains open for the short time, the database management system does not get flooded with the incoming requests.
 
What are the performance considerations when using dataset?
Since no memory buffer is maintained by the data reader, it takes up fewer resources and performs more efficiently with small number of data operations. The dataset, on the other hand is more efficient when large number of updates are to be made to the database. All the updates are done in the local memory and are updated to the database in a batch. Since database connection remains open for the short time, the database management system does not get flooded with the incoming requests.
However, since the dataset stores the records in the local buffer in the hierarchical form, it does take up more resources and may affect the overall performance of the application.
 
How to select dataset or data reader?
The data reader is more useful when you need to work with large number of tables, database in non-uniform pattern and you need not execute the large no. of queries on few particular table.
When you need to work on fewer no. of tables and most of the time you need to execute queries on these fewer tables, you should go for the dataset.
It also depends on the nature of application. If multiple users are using the database and the database needs to be updated every time, you must not use the dataset. For this, .Net provides the connection oriented architecture. But in the scenarios where instant update of database is not required, dataset provides optimal performance by making the changes locally and connecting to database later to update a whole batch of data. This also reduces the network bandwidth if the database is accessed through network.
Disconnected data access is suited most to read only services. On the down side, disconnected data access architecture is not designed to be used in the networked environment where multiple users are updating data simultaneously and each of them needs to be aware of current state of database at any time (e.g., Airline Reservation System).

How XML is supported in ADO.Net?
The dataset is represented in the memory as an XML document. You can fill the dataset by XML and can also get the result in the form of XML. Since XML is an international and widely accepted standard, you can read the data using the ADO.Net in the XML form and pass it to other applications using Web Service. These data consuming application need not be the essentially Dot Net based. They may be written with Java, C++ or any other programming language and running on any platform.



 

Asp.NET Important Question And Answer

1) Which of the following languages can be used to write server side scripting in ASP.NET?
a) C-sharp
b) VB
c) C++
d) a and b


2) When an .aspx page is requested from the web server, the out put will be rendered to browser in following format.
a) HTML
b) XML
c) WML
d) JSP

3) The Asp.net server control, which provides an alternative way of displaying text on web page, is
a) <>
b) <>
c) <>

4) The first event to be triggered in an aspx page is.
a) Page_Load()
b) Page_Init()
c) Page_click()

5) Postback occurs in which of the following forms.
a) Winforms
b) HTMLForms
c) Webforms

6) What namespace does the Web page belong in the .NET Framework class hierarchy?
a) System.web.UI.Page
b) System.Windows.Page
c) System.Web.page


7) Which method do you invoke on the Data Adapter control to load your generated dataset?
a) Fill( )
b) ExecuteQuery( )
c) Read( )

8) How do you register a user control?
a) Add Tag prefix, Tag name
b) Add Source, Tag prefix
c) Add Src, Tagprefix, Tagname

9) Which of the following is true?
a) User controls are displayed correctly in the Visual Studio .NET Designer
b) Custom controls are displayed correctly in VS.Net Designer
c) User and Custom controls are displayed correctly in the Visual Studio .NET Designer.

10) To add a custom control to a Web form we have to register with.
a) TagPrefix
b) Name space of the dll that is referenced
c) Assemblyname
d) All of the above

11) Custom Controls are derived from which of the classes
a) System.Web.UI.Webcontrol
b) System.Web.UI.Customcontrol
c) System.Web.UI.Customcontrols.Webcontrol

12) How ASP.Net Different from classic ASP?
a) Scripting is separated from the HTML, Code is interpreted seperately
b) Scripting is separated from the HTML, Code is compiled as a DLL, the
DLLs can be executed on server

c) Code is separated from the HTML and interpreted Code is interpreted separately

13) What's the difference between Response.Write() andResponse.Output.Write()?
a) Response.Output.Write() allows you to flush output
b) Response.Output.Write() allows you to buffer output
c) Response.Output.Write() allows you to write formatted output
d) Response.Output.Write() allows you to stream output

14) Why is Global.asax is used?
a) Implement application and session level events
b) Declare Global variables
c) No use

15) There can be more than 1 machine.config file in a system
a) True
b) False

16) What is the extension of a web user control file?
a) .Asmx
b) .Ascx
c) .Aspx

17) Which of the following is true?
a) IsPostBack is a method of System.UI.Web.Page class
b) IsPostBack is a method of System.Web.UI.Page class
c) IsPostBack is a readonly property of System.Web.UI.Page class

8) The number of forms that can be added to a aspx page is.
a) 1
b) 2
c) 3
d) More than 3


19) How do you manage states in asp.net application
a) Session Objects
b) Application Objects
c) Viewstate
d) All of the above

20) Which property of the session object is used to set the local identifier?
a) SessionId
b) LCID
c) Item
d) Key

21) Select the caching type supported by ASP.Net
a) Output Caching
b) DataCaching
c) a and b
d) none of the above

22) Where is the default Session data is stored in ASP.Net?
a) InProcess
b) StateServer
c) Session Object
d) al of the above

23) Select the type Processing model that asp.net simulate
a) Event-driven
b) Static
c) Linear
d) Topdown

24) Does the EnableViewState allows the page to save the users input on a form?
a) Yes
b) No

25) Which DLL translate XML to SQL in IIS?
a) SQLISAPI.dll
b) SQLXML.dll
c) LISXML.dll
d) SQLIIS.dll

26) What is the maximum number of cookies that can be allowed to a web site?
a) 1
b) 10
c) 20
d) More than 30

27) Select the control which does not have any visible interface.
a) Datalist
b) DropdownList
c) Repeater
d) Datagrid


28) How do you explicitly kill a user session?
a) Session.Close( )
b) Session.Discard( )
c) Session.Abandon
d) Session.End
e) Session.Exit

29) Which of the following is not a member of ADODBCommand object?
a) ExecuteReader
b) ExecuteScalar
c) ExecuteStream
d) Open
e) CommandText

30) Which one of the following namespaces contains the definition for IdbConnection?
a) System.Data.Interfaces
b) System.Data.Common
c) System.Data
d) System.Data.Connection

Feb 10, 2010

Building ASP.NET UserControls

Introduction

If you are Classic ASP programmer or PHP programmer, you probably use SSI include files quite a lot on your web applications and you probably also know that this has worked quite reasonably well for all of you. But the major disadvantages would be maintaining the code once your web projects has grow bigger. Major problem would be to keep up with the HTML opening and closing tags. Its quite hard to debug the code if you are adding some HTML files in your include files and then later on you find that it produce funny result on certain page. There are no visual GUI or IDE that can help you to see the design view. The only way to debug is by viewing the page in the browser. This has taken quite a lot of developer time. The code was also very messy and also you might need to include all your include files in correct order and lots of developer normally will do copy and paste for all their page.

Luckily in ASP.NET technology, this problem has been solved with the introduction of UserControl. UserControl is basically use the same technology like the SSI includes except that it is a self contained objects where you can set the properties,attributes and methods. UserControl also can be designed using Visual Studio design view which allow you to see the layout of your page nicely.

Main

In this article, I will be presenting some simple example of my existing projects that use UserControls.
We will be doing some Header and Footer UserControls that expose some properties and attributes.
Now, let's start writing some code for creating UserControl.

Open Visual Studio 2005, Add New Web Site and Choose to add New UserControl. First one should be named as Header.ascx and second one as Footer.ascx.

If you look at the HTML source for the user control, you see several interesting differences from a standard ASP.NET Web Page
<%@ CONTROL LANGUAGE="C#" AUTOEVENTWIREUP="true" CODEFILE="Header.ascx.cs" I

INHERITS="UserControl_Header" %>
First,notice that the source uses @Control directive rather than @Page directive which a standard Web page would use. Second, notice that unlike a standard ASP.NET Web Page,no other HTML tags such as body,or DIV exists on the control. The web page containing the user control provides the basic HTML tags such as and
tags.In fact if you try to add server side form tags to the user control,ASP.NET will returns an error when the page is served to the clients.

Now, add this code into your Header.ascx
<%@ CONTROL LANGUAGE="C#" AUTOEVENTWIREUP="true" CODEFILE="Header.ascx.cs" INHERITS="Header" %>

<TABLE BORDER="0" WIDTH="100%">

   <TR>

       <TD>

           I am header User Control.TD>

       <TD>

           Today Date is <%=Date %>

       TD>

       <TD>

           Our Phone Number is <%=PhoneNumber %>

       TD>

   TR>

   <TR>

       <TD COLSPAN="3" BGCOLOR=<%=BgColor %>>

           <ASP:MENU ID="Menu1" RUNAT="server" ORIENTATION="Horizontal" WIDTH="100%" BACKCOLOR="#B5C7DE"

                DYNAMICHORIZONTALOFFSET="2" FONT-NAMES="Verdana" FONT-SIZE="0.8em" FORECOLOR="#284E98"

                STATICSUBMENUINDENT="10px">

               <ITEMS>

                   <ASP:MENUITEM TEXT="Home" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Our Products" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Our Features" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="About Us" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Contact Us" VALUE="New Item">ASP:MENUITEM>

                   <ASP:MENUITEM TEXT="Why Choose Us" VALUE="New Item">ASP:MENUITEM>

               ITEMS>

               <STATICMENUITEMSTYLE HORIZONTALPADDING="5px" VERTICALPADDING="2px" />

               <DYNAMICHOVERSTYLE BACKCOLOR="#284E98" FORECOLOR="White" />

               <DYNAMICMENUSTYLE BACKCOLOR="#B5C7DE" />

               <STATICSELECTEDSTYLE BACKCOLOR="#507CD1" />

               <DYNAMICSELECTEDSTYLE BACKCOLOR="#507CD1" />

               <DYNAMICMENUITEMSTYLE HORIZONTALPADDING="5px" VERTICALPADDING="2px" />

               <STATICHOVERSTYLE BACKCOLOR="#284E98" FORECOLOR="White" />

           ASP:MENU>

       TD>

   TR>

TABLE>





From the code above, you notice that we use lots of server side tags <%=%> in the ascx file. The reason is because all that values is taken from the usercontrol properties and we can set the properties from the hosted user control page. The idea was be able to set and get the properties from the page.
In this example, we can set the background color of the user page, set the title and set the Date.

Now, add this code into Header.ascx.cs
using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;



public partial class Header : System.Web.UI.UserControl

{

   private string sTitle = "Welcome to My Company";

   private string sPhoneNumber = "12345667";

   private string sDate = "12/12/2007";

   private string sBgColor = "white";

   protected void Page_Load(object sender, EventArgs e)

   {



   }

   public string BgColor

   {

       get

       {

           return sBgColor;

       }

       set

       {

           sBgColor= value;

       }

   }

   public string Title

   {

       get

       {

           return sTitle;

       }

       set

       {

           sTitle = value;

       }

   }

   public string PhoneNumber

   {

       get

       {

           return sPhoneNumber;

       }

       set

       {

           sPhoneNumber = value;

       }

   }

   public string Date

   {

       get

       {

           return sDate;

       }

       set

       {

           sDate = value;

       }

   }



}
From the code above, you can see that we provide public get and set methods for all the properties that we use in Header.ascx file. We also provide default properties values for that incase if the UserControl does not override the property value.

Adding UserControl into Page

To add User Controls to the form, you can do it in two ways.
First, would be easy ways, but you need to have Visual Studio.
Open your Visual Studio in design View, and then drag the Header.ascx from SolutionExplorer into your Page. Once you do that, you can see that Visual Studio does all the necessary code for you.

Second way, would be manually code the UserControl in your page.
Add the Register directives as below
<%@ REGISTER src="Header.ascx" TAGNAME="Header" TAGPREFIX="uc1" %>
You can named the TagName and TagPrefix as you like. After that add the UserControl to the location you want on your page. The tag for user control should be like this
<UC1:HEADERS ID="Header1" RUNAT="server" TITLE="Hello Here" BGCOLOR="red"

PHONENUMBER="123455" />
Notice that in the UserControl above, we can define all the properties that we have previously provide public set methods.

You can also set and get the UserControl properties in code behind.
To get and set the UserControl properties, you can use code like this in your code behind
e.g Header1.Title = "Yes";
or Response.Write(Header1.Title);

UserControls is infact an object in your Page. You can add as many usercontrol on your page, or on multiple page. Each individual UserControl you add can have different set of properties and methods you can call.

Conclusion

ASP.NET UserControl is the new way of encapsulate all your code reuse in your web applications. Old way of doing this would be via SSI includes which can be very messy and very hard to maintain if your site grow. ASP.NET UserControl is infact the simplest form of ASP.NET control encapsulation. Because they are the simplest, they are also the easiest to create and use. Essentially user control is a grouping of existing server controls into a single container control. This enables you to group all your reusable part of webpage into UserControl. The basic example would be Login Controls, News Controls, Header Controls and etc.

If However you want to create your own controls from scratch that has the features like ASP.NET Web Server controls (Label,Button,TextBox), then you need to create the controls as Custom Controls. Custom controls is not discussed in this article.

Get current page name

This function can be used to retrieve the current page:s name, i.e default.aspx, hello.aspx or whatever.


public string GetCurrentPageName()
{
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}


By going through System.Web.HttpContext.Current object we are able to have this function in a generic dll or class - and not in each and every page needing to call it.

Nov 20, 2009

Register IIS

Sounds like a permissions issue.

Can you try running %windir%\microsoft.net\framework\v2.0.50727\aspnet_regiis -i -enable

That should reset the permissions and reregister ASP.Net on your server.