c#

How to restrict access to all application pages in C#

Web developer follows the approach described in the article, when he/she has to restrict access to the pages of his/her application to authorized users only. In this case Web developer should change the web.config settings of his/her application to specify Forms authentication, and then create an .aspx login page to collect user credentials and complete the authentication check.

Web …

Learn more

How to use Ajax partial rendering in C#

Let start with a classical example – Web developer works under application which has a Web page with two drop-down lists. The first one contains all the cities in the country, and the second one contains the bank branches locations in the selected city. Web developer needs to populate the second drop-down list with the correct locations each …

Learn more

How to read XML file in C#

Suppose that the user has to read the XML file he/she already generated. The application should provide functionality to extract all vendors from Canada, and after that the user has to process them in alphabetic order.

 

Web developer has to follow these steps:
   1.Create the XDocument using the XML.
   2.Navigate the XElement elements to reach the Vendor ones.
   3.Take the XElement instances …

Learn more

How to generate XML from data source in C#

Let’s Web developer has to develop a page where the user submits a file containing the ISBN of all the books he/she needs information about. The user has to retrieve these books and create an XML file with the book title, author and price.

Web developer can use a LINQ query to pass child elements and nest data, by …

Learn more

How to create an XML file by using LINQ to XML in C#

In .NET Framework 4.0 the System.Xml APIs are obsolete and are maintained for compatibility reasons only.  Web developers can create XML file by using LINQ to XML. The next picture presents classes in LINQ to XML.
 
 
 
 
 
 
 
 

The classes in LINQ to XML

 

These classes are included in System.Xml.Linq namespace and the following ones are the most …

Learn more

How to use session state in ASP.NET using C#

Software developer can interact with session state using the  System.Web.SessionState.HttpSessionState class, which is provided in an ASP.NET web page as the built-in Session object. Items can be added to the collection and retrieved after in the same manner as items can be added to a page’s view state:

For example, software developer might store a string in memory like …

Learn more

How to transfer information between pages in ASP.NET using a query string in C#

Software developer can use this approach for information that don’t need to be hidden or made tamper-prof. Unlike view state information passed through the query string is clearly visible and unencrypted. The query string is the portion of the URL after the question mark in the following example:

https://www.google.com?q=look+for+aspnet+code

Software developer can store information in the query string himself using …

Learn more

How to store custom objects in a View state using C#

Software developer can store custom objects in a view state just as easily as regular types. However, to store an item in a view state, ASP.NET must be able to convert it into a stream of bytes. This process is called serialization. If developer’s objects aren’t serializable, he will receive an error message when he attempts to place …

Learn more

How to set focus on control in C#

You can put the focus on the following types of ASP.NET controls: Button, LinkButton, and ImageButton controls, CheckBox control, DropDownList control, FileUpload control, HyperLink control, ListBox control, RadioButton control, TextBox control.

The following C# code example shows how to set the focus on the control with the ID TextBox1:

protected void Page_Load(object sender, EventArgs e)
{
    TextBox1.Focus();
}

Related TutorialsHow to change the text …

Learn more