Monday, April 27, 2009

ASP.NET 2.0 : Cross Page Posting

Cross Page Posting in ASP.NET 2.0

By default, button controls in ASP.NET pages post back to the same page that contains
the button, where you can write an event handler for the post. In most cases this is the
desired behavior, but occasionaly you will also want to be able to post to another page in
your application. The Server.Transfer method can be used to move between pages, however
the URL doesn't change. Instead, the cross page posting feature in ASP.NET 2.0 allows
you to fire a normal post back to a different page in the application. In the target page,
you can then access the values of server controls in the source page that initiated the post
To use cross page posting, you can set the PostBackUrl property of a Button, LinkButton
or ImageButton control, which specifies the target page. In the target page, you can then
access the PreviousPage property to retrieve values from the source page. By default, the
PreviousPage property is of type Page, so you must access controls using the FindControl
method. You can also enable strongly-typed access to the source page by setting the
@PreviousPageType directive in the target page to the virtual path or Type name of the
source page.
Here is a step-by-step guide for implementing the cross-page post back using controls
that implement the IButtonControl interface.
√ Create a Web Form and insert a Button control on it using the VS .NET designer.
√ Set the button's PostBackUrl property to the Web Form you want to post back. For
instance in this case it is "nextpage.aspx"
PostBackUrl="~/nextpage.aspx" Text="Post to nextpage" />
When the PostBackUrl property of the IButtonControl is set, the ASP.NET framework
binds the corresponding HTML element to new JavaScript function named
WebForm_DoPostBackWithOptions. The corresponding HTML rendered by the ASP.NET
2.0 will look like this:
< input type="submit" name="Button1" value="Post to Page 2"
WebForm_PostBackOptions("Button1", ",false”,"Page2.aspx", false, false))"
id="Button1" / >

How do we access viewstate value of this page in the next page ?
View state is page specific; it contains information about controls embedded on the
particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name,
__POSTBACK . This field is embedded only when there is an IButtonControl on the
page and its PostBackUrl property is set to a non-null value. This field contains the view
state information of the poster page. To access the view state of the poster page, you can
use the new PreviousPage property of the page:
Page poster = this.PreviousPage;
Then you can find any control from the previous page and read its state:
Label posterLabel = poster.findControl("myLabel");
string lbl = posterLabel.Text;
This cross-page post back feature also solves the problem of posting a Form to multiple
pages, because each control, in theory, can point to different post back URL.

Can we post and access view state in another application?

You can post back to any page and pages in another application, too. But if you are
posting pages to another application, the PreviousPage property will return null. This is a
significant restriction, as it means that if you want to use the view state, you are confined,
for example, posting to pages in the same virtual directory. Even so, this is a highly
acceptable addition to the functionality of ASP.NET.

Tuesday, April 21, 2009

Difference between Design Pattern & Framework

A framework is a set of collaborative classes for a specific application that can be reused (API) following a predefined design.

A general specification that is collection Of classes and Interfaces APIs that are designed to work together to handle a particular type of Problem. Framework is a skeleton of code used for developing an application.

Eg: Struts based framework
(Action Classes, Configuration Files) grouped together called Framework

a framework is a finite solution that help you structure your code and solve a particular kind of problems. A framework is usually made of several patterns implementation. A framework is based upon the IoC (Inversion of Control) principle; your application just need to provide and declare some callback functions and start the framework. From there the framework is in charge of running the application, calling your callback functions whenever it's necessary. So as you can see, they are very different concepts, the main difference being that a framework is a physical and usable piece of code while a pattern is a logical design solution to a given kind of problem.

Design Pattern :

Best practice for solving a common problem.

Design Patterns is a solution for recursively occured problem. These patterns wont have sperate API.

A Design pattern is a way of doing common things in a special way .Each known pattern has evolved from the failures of many programs that had been written in various domains.The most effective way of dealing with a problem is documented in a given style recommended by GoF (Gang of Four). The patterns themselves are useless is not applied properly and needs some experiance in writing solutions and different scenarious has to be taken in mind. The pattern that is in close resemblance with the problem at hand is the pattern to work with. Patterns are tried and tested ways of writing programs better but dont be too hasty to apply them with a blind eye. They need patience and a sharp eye of distinction. Patterns are also related closely with the logic and the code.

A pattern may not be restricted to programs only. It extends to the database level too.

Tuesday, April 14, 2009

Postgres Windows install problem. Error 'User Doesnot Exists'

I Installed postgre using the windows installer and later on did a uninstall.
Later when i tried installing again, the installer never allowed me to install with the normal settings of User Postgre and superuser Postgre
It always gave me the error
'User Doesnot exists'.

or Unable to install, Security name Not mapped to the UserID

Windows machine :
Go to your Control Panel -> User Accounts ->Advanced -> Advanced USer Management Advanced USer Management -> Advanced

You would be seeing all the Local Users/Groups

you would find the intial username used while installing Postgre.

You can right click -> delete

or create a New User and make him a normal User group
and then use the same username while postgre install.