Posts Tagged ASP.NET

SuzanneASP.NET 4 and Visual Studio 2010 Released

Thursday, April 15th, 2010

ASP.NET 4 and Visual Studio 2010 are released, which include lots of new features and improvements that enable the developers to build, deploy and manage great Web sites and applications.

Need to Build Better Websites-

Visual Studio 2010
Visual Studio 2010 makes it easier to edit, search, and navigate code. Improved VB and C# Intellisense makes it even easier to find and use classes within the .NET Framework. Improved JavaScript IntelliSense enables better AJAX development.

New code navigation and visualization features enable to find quickly and navigate large projects and visualize dependencies across your code-base. Improved unit testing, debugging and profiling help support builds robust applications.

ASP.NET Web Forms
With ASP.NET 4, Web Forms controls now render clean, semantically correct, and CSS friendly HTML markup. Built-in URL routing functionality allows you to expose clean, search engine friendly, URLs and increase the traffic to your Website.
ViewState within applications is smaller and can now be more easily controlled. And more controls, including rich charting and data controls, are now built-into ASP.NET 4 and enable you to build applications even faster.

ASP.NET MVC
ASP.NET MVC 2 is now built-into VS 2010 and ASP.NET 4, and provides a great way to build web sites and applications using a model-view-controller based pattern. ASP.NET MVC 2 adds features to easily enable client and server validation logic, provides new strongly-typed HTML and UI-scaffolding helper methods, enables more modular/reusable applications, and facilitates a clean unit testing and TDD workflow with Visual Studio 2010.

Web Deployment
Visual Studio 2010 makes deploying your Websites easy. You can now publish your Websites and applications to a staging or production server from within Visual Studio itself.

Visual Studio 2010 makes it easy to transfer all your files, code, configuration, database schema and data in one complete package. VS 2010 also makes it easy to manage separate web.config configuration files settings depending upon whether you are in debug, release, staging or production modes.

Tags: , , , , , ,
Posted in New Product Release | No Comments »

SuzanneDynamically Setting the Theme

Tuesday, March 9th, 2010

Themes can be used to customize the look of your Website. If you need to select the theme based on user settings, you’ll be glad to know that ASP.NET allows you to set the theme of a page dynamically when the page is being created. This process is pretty straight forward; however, there are a couple of issues that may arise.

First of all, ASP.NET establishes the current theme prior to the page’s Load() event. In order to dynamically change the theme before the Load() event, you’ll need to set it during the page’s PreInit() event.

Setting the Theme in the PreInit() Event

That was easy enough. But what happens if your site uses a master page? Master pages allow you to control the appearance of all the pages on your site from a single master page. So it makes sense to want to set the theme from the master page. However, master pages do not provide a PreInit() event. So setting the theme dynamically from a master page is not as easy as you might guess.

One way to deal with this is to create a class that derives from IHttpModule. This class can be made to respond to all page requests on your site, and it gets called just before the request is handled, in plenty of time to set the theme for the current page.

public class ThemeManager : IHttpModule
{
   public ThemeManager()
    {
    }
  public void Init(HttpApplication app)
    {
        // Set our handler to be called just before handling a request
        app.PreRequestHandlerExecute +=
            new EventHandler(Context_PreRequestHandlerExecute);
    }
  void Context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        // Note: If handler does not implement IRequiresSessionState or
        // IReadOnlySessionState then Session state will be unavailable
        if (HttpContext.Current.CurrentHandler is Page)
        {
            // Set theme
            Page page = (Page)HttpContext.Current.CurrentHandler;
            page.Theme = "MyTheme";
        }
        public void Dispose()
        {
        }
    }
}

Setting the Theme from an IHttpModule-Derived Class

In order to use this class, you’ll have to modify your web.config file.

<configuration>
 <system.web>
 <httpModules>
 <add />
 </httpModules>
 </system.web>
</configuration>

Web.config Changes

Also, be sure to clear any theme settings from your web.config file. Otherwise, it’s possible for ASP.NET to get confused and possibly reference multiple CSS files.

ASP.NET themes are quite powerful, and can be used to manage the appearance of various controls and images. Another thing themes do is let you specify CSS, or style sheets. If this is all your themes are used for, then a much simpler approach can be taken.

All you need to do is add a Literal control inside of the <head> section of your master page. Then, you can set it to include your style sheet during the master page’s Load event.

Since you aren’t modifying the look of controls using skins, there is no need to change this setting in the PreInit() handler. In fact, you could handle it even later than the Load event since all that needs to happen is your page references the correct CSS file.

http://www.all1tunes.com

http://www.all1social.com

Tags: , , , , , , , ,
Posted in Microsoft Technology | No Comments »

SuzanneASP.Net Compilation Tool – do you want to allow updates without redeploying?

Saturday, March 6th, 2010

If we have an ASP.Net website that:
1. We want to pre-compile before deploying to the live servers for the usual reasons of performance (no delay on first hit) and security (source code not hosted on the servers)
2. Before starting the web application, we automatically generate its web.config file
3. By default we want to disable view state in all the pages by adding a
node in the generated web.config
The main issue was that even though the generated web.config file had the correct setting in it, the view state wasn’t being disabled. This confused us for quite a while.
It turns out that the default setting when a website is compiled by the ASP.Net compiler doesn’t allow subsequent updates to the site.
In our particular case, this meant the compiled pages were using the (default) value in our non-existent web.config at compile time, not the one actually on the server at runtime.
Once we realised that, the solution was easy: simply add a –u parameter to the compiler flags which meant:
-u specifies that the Aspnet_compiler.exe should create a precompiled application that allows subsequent updates of contents such as .aspx pages.
If this option is omitted, the resulting application contains only compiled files and cannot be updated on the deployment server. You can update the application only by changing the source markup files and recompiling.

http://www.all1Press.com

http://www.all1tunes.com

http://www.all1social.com

Tags: , , , , ,
Posted in Microsoft Technology | No Comments »

Naggie4 Steps to Consume Web Services using Ajax

Thursday, March 4th, 2010

Normally the browser Ajax controls calls the ASP.NET code and the ASP.NET code consumes the web service, but there are scenarios where you would like to call the web services directly from the Ajax JavaScript functions rather than calling via the behind code.

Here, you can get the same following 4 steps-

Step 1: Create your Customer Class

The first step is to create the customer class as shown below. So the customer class has 4 properties on customer id, first name, address and designation.

public class Customers
{
// private properties
private int _intCustomerID;
private string _strFirstName;
private string _strAddress;
private string _strDesignation;

// Public property and
public int CustomerID
{
get
{
return _intCustomerID;
}
set
{
_intCustomerID = value;
}
}
public string FirstName
{
get
{
return _strFirstName;
}
set
{
_strFirstName = value;
}
}

public class Customers
{
// private properties
private int _intCustomerID;
private string _strFirstName;
private string _strAddress;
private string _strDesignation;
// Public property and
public int CustomerID
{
get
{
return _intCustomerID;
}
set
{
_intCustomerID = value;
}
}
public string FirstName
{
get
{
return _strFirstName;
}
set
{
_strFirstName = value;
}
}

Step 2: Create your Web Service

The next step is to create the web service which exposes the customer class to UI. Here is a simple web service which has encapsulated customer collection. In the constructor, we are loading some dummy data into the list of customers as shown in the below code snippet:

[System.Web.Script.Services.ScriptService]
public class Customer : System.Web.Services.WebService {

// Customer collection
List<Customers> listcust = new List<Customers>();
public Customer ()
{
//Load some dummy data in to customer collection.
listcust.Clear();

Customers cust = new Customers();
cust.CustomerID = 1;
cust.FirstName = “Dan”;
cust.Address = “Live in UK”;
cust.Designation = “Software Developer”;
listcust.Add(cust);

cust = new Customers();
cust.CustomerID = 2;
cust.FirstName = “Sheen”;
cust.Address = “Live in Austrailia”;
cust.Designation = “Web Designer”;
listcust.Add(cust);

cust = new Customers();
cust.CustomerID = 3;
cust.FirstName = “Koraine”;
cust.Address = “Live in London”;
cust.Designation = “Architect”;
listcust.Add(cust);
}

// This function exposes all customers to the end client’
[WebMethod]
public List<Customers> LoadCustomers()
{
return listcust;
}

// This function helps us to get customer object based in ID
[WebMethod]
public Customers LoadSingleCustomers(int _customerid)
{
return (Customers)listcust[_customerid-1];
}

Two functions have been exposed with the web service, one which gives out a list of customers and another which gives out individual customer data based on customer id.

Step 3: Reference your Web Service using the asp:servicereference

Using the ‘asp:ServiceReference’, the path to the ASMX file will be pointed as shown in the below code snippet. This will generate the JavaScript proxy which can be used to call the customer object.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="Customer.asmx" />
    </Services>
</asp:ScriptManager>

Step 4: Call the Webservice and the JavaScript Code

Once you have defined the proxy, you can now call the ‘Customer’ proxy directly to make method calls.

function LoadAll()
{
Customer.LoadCustomers(LoadCustomerToSelectOption, ErrorHandler, TimeOutHandler);
}

When you call the JavaScript proxy object, then you need to provide three functions; the first function (‘LoadCustomerToSelectOption’) will be called when the web service finishes and returns data. The data will be returned in the fill variable which will then be looped and added to the customer combo box.

function LoadCustomerToSelectOption(Fill)
{
var select = document.getElementById(”cmbCustomers“);

for (var i = 0; i < Fill.length; i++)
{
var value = new Option(Fill[i].FirstName, Fill[i].CustomerID);
select.options.add(value);
}
}

There are two more functions which are attached; one which handles error and the other which handles time out.

function ErrorHandler(result)
{
var msg = result.get_exceptionType() + “\r\n“;
msg += result.get_message() + “\r\n“;
msg += result.get_stackTrace();
alert(msg);
}
function TimeOutHandler(result)
{
alert(”Timeout :” + result);
}

http://www.all1martpro.com
http://get-a-designer.com

Tags: , , , , , ,
Posted in Microsoft Technology, Purely Technical | No Comments »

SuzannePostback Text Processing with the AJAX Modal Dialog

Friday, February 26th, 2010

In this case the developer wanted to use an AJAX Editor Control inside a ModalPopup control.

This isn’t a problem but, the user needed to clicking the OK button to cause a post-back so that he could execute some server –side logic.

The ”Ok” Button is an ASP.NET control but adding a Click Event Handler for the button didn’t solve the problem because it didn’t get executed when the use Clicked on the “Ok” button.

Normally the ModalPopupExtender would be used like this.

    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                 TargetControlID="LinkButton1"
                 PopupControlID="Panel1"
                 BackgroundCssClass="modalBackground"
                 DropShadow="true"
     1.)         OkControlID="OkButton"
     2.)         OnOkScript="onOk()"
                 CancelControlID="CancelButton" />

Line number 1 tells the control to catch the click event for the Ok Button Control instance and line 2 specifies when CLIENT SIDE JavaScript code to execute when the control specifies in line 1 is clicked.

The post-back doesn’t happen (even if the ASP.NET Button control has a click event handler defined in code behind because the control doesn’t propagate it.)

So Just delete those two lines !

It turns out that they are optional and if you delete them the click event is not trapped and the code behind will execute as expected.

So just nake it look like this:

    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                 TargetControlID="LinkButton1"
                 PopupControlID="Panel1"
                 BackgroundCssClass="modalBackground"
                 DropShadow="true"
                 CancelControlID="CancelButton" />

http://www.all1sourcetech.com

http://www.all1martpro.com

Tags: , , , , ,
Posted in Microsoft Technology, Purely Technical | No Comments »

NaggieVisual Studio 2010 clean application level web.config

Friday, February 19th, 2010

Introducing new small improvement that has been made in Visual Studio 2010 & .NET 4 to reduce the size of the ASP.NET application level web.config 3.0 and 3.5 web.config

As ASP.NET technology evolved, the application level Web.config had new things added to it. Since the earlier frameworks were using the same set of machine level configuration files, incremental feature that was added subsequent to the 2.0 release resulted in additional config settings included in the file.
.NET 4 web.config

With .NET 4, the web.config is tremendously reduced in size to improve the simplicity of ASP.NET

The config settings have been moved down to the machine config file. This includes registers all of the ASP.NET tag sections, handlers, modules and settings for the following:
• ASP.NET AJAX
• ASP.NET Dynamic Data
• ASP.NET Routing
• ASP.NET Chart Control

You can look at the trimmed down web.config by creating a .Net 4 ‘ASP.NET Empty Web Application’ in Visual Studio 2010.

Following is the web.config file for .NET 4 C# ‘ASP.NET Empty Web Application’:

image thumb Visual Studio 2010 clean application level web.config

The config file above has settings to tell ASP.NET to enable debugging by default for the application and provides the version of .NET framework to use.

http://www.all1tunes.com

http://www.all1social.com

Tags: , , , , , , ,
Posted in Microsoft Technology, Purely Technical | No Comments »

NaggieDownload ASP.NET MVC 2 RC 2

Saturday, February 6th, 2010

ASP.NET MVC 2 RC 2 provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 SP1 runtime.

ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern. The framework encourages developers to maintain a clear separation of concerns among the responsibilities of the application – the UI logic using the view, user-input handling using the controller, and the domain logic using the model. ASP.NET MVC applications are easily testable using techniques such as test-driven development (TDD).

The installation package includes templates and tools for Visual Studio 2008 SP 1 to increase productivity when writing ASP.NET MVC applications. For example, the Add View dialog box takes advantage of customizable code generation (T4) templates to generate a view based on a model object. The default project template allows the developer to automatically hook up a unit-test project that is associated with the ASP.NET MVC application.

Because the ASP.NET MVC framework is built on ASP.NET 3.5 SP 1, developers can take advantage of existing ASP.NET features like authentication and authorization, profile settings, localization, and so on.

System Requirements

-Supported Operating Systems: Windows 7; Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP

.NET 3.5 SP1. Visual Studio 2008, Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 are required to use certain parts of this feature.

http://get-a-designer.com

http://www.all1sourcetech.com

Tags: , , , , , , , ,
Posted in Microsoft Technology, New Product Release, Technical News | No Comments »