Thursday, October 11, 2007

Setting focus to control in Asp.NET 2

I'm building a website (as i told in my previous post). In one form i used wizard control. The problem was that the form is in master page, which itself contains navigation bar as header of the site. When page loaded, the control will go to links and controls on the master form first and then to controls in this form.

I googled and found nice snippets of Javascript and even a control class on codeproject. But I tried to go the easier way first. So in page_load event I tried like dropdownlist1.Focus() and voila it worked.

Next was to see on which step the wizard is, which I was already doing to validate the inputs from user, and set the focus to first control on next page of wizard.

There was a postback also, where a dropdown list changes and loads another one. In postback handler (dropdownlist2_selectedindexchanged) at the end, I wrote dropdownlist3.Focus() and it was working here too.

Hope it helps you.

Saturday, October 6, 2007

Another reason for "Failed to Update Database ..\App_Data\aspnet.mdf because database is readonly

I am currently working on ASP.NET 2 project. After working for 2 days and creating an outline for the site and flow for user interaction, I decided it was right time to put it into source control.

After I added it to source control it started giving me giving strange "database is read-only problem". I googled a bit about it. The solutions offered ranged from giving IIS process, ASPNET user and don't remember who else to give access to app_data folder. But it did not work.

Then there was an elaborate solution using command line sseutil . It recommended to detach the database and reattach it. After some futile attempts, I had to close VS, and restart Sql Express.

Again today some how I checked in all the files in solution and it again gave gave me same problem when I tried to create a Stored Procedure. Then occurred to me that maybe it is because the database file is checked in source control and is read-only (it was checked in). I detached it (with sseutil of course), checked out the file (aspnet.mdf) and it is working again alright.