How to Solve a Common Problem With Asp.net Formview Defaultstate Property

The ASP.NET FormView WebControl is one of the most useful items you can find in the Microsoft Visual Studio .NET Toolbar, now, although is extremely easy to use, you can make mistakes and walk in circles just because you forgot a simple click, especially when using the DefaultState property.

This property defines the “default” state for the webcontrol after an insert/update/delete operation, that is, the state to wich the control will return after any of those operations are perfomed. So, the property DOES NOT CHANGE the current FormView’s state, to do that use the ChangeState method instead. Check this c# code:

//Sets the default mode after a delete/insert/update operation
FormView1.DefaultMode = FormViewMode.ReadOnly;
//This changes the formview's state
FormView1.ChangeMode(FormViewMode.Insert);

A common problem is when you are linking a FormView to a GridView (to do a master-details), if you notice that the behavior is not what you want; check what you are doing with that property. Setting the default value to “ReadOnly” usually works fine. If you need to “change” the state of the FormView because of your programming logic, try the ChangeState method.

Add This! Blinkbits Blinklist Blogmarks BlogMemes BlueDot BlogLines co.mments Connotea del.icio.us de.lirio.us Digg Diigo DZone Facebook FeedMeLinks Folkd.com Fleck Furl Google Google Reader icio.de IndianPad Leonaut LinkaGoGo Linkarena Linkter Magnolia Mister Wong MyShare Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Netvouz Newsgator Newsvine Oneview.de RawSugar reddit Rojo Segnalo Shadows Simpy SlashDot Smarking Sphere Spurl Startaid StumbleUpon TailRank Technorati ThisNext yigg.de Webnews.de ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com Plugin by Dichev.com

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.