Inka has finally changed its Unix name at SourceForge. You can find it at https://sourceforge.net/projects/inka.
Also, I'm finally building me a site, and there'll be a lot about Inka and how it should be used. Find it at http://sm-art.biz.
Monday, 11 February 2008
Tuesday, 29 January 2008
Binding It Twice
Last week I, like a lot of other Asp.Net newbies, got a weird validation error on my page saying, "Invalid postback or callback argument". The funny thing is, I've got another error two days earlier, even more weird, saying,
What caused the error in both cases was calling the DataBind method on postback, which you shouldn't usually do if you have ViewState enabled. In the second case, I blindly called DataBind on the page itself.
So, the rule for other newbie who happen to read this:
Whenever you init your page, call DataBind for the GridView only if you haven't set the DataSourceID, and always wrap it with "If Not IsPostBack".
If you add/change your record via a DetailsView that is bound to the same DataSource, you don't have to call DataBind on postback, since the DataSource will notify the GridView of the change.
If you add/change your record via some other means, call DataBind after it has been changed.
Here's my stack trace for Google:
Item has already been added. Key in dictionary: 'ID' Key being added: 'ID'
The weird thing about this error is that I was adding an item to a GridView via a regular mechanism, using the prescribed DetailsView and ObjectDataSource, no funky MVP stuff. The "ID" in this error refers to the key column.What caused the error in both cases was calling the DataBind method on postback, which you shouldn't usually do if you have ViewState enabled. In the second case, I blindly called DataBind on the page itself.
So, the rule for other newbie who happen to read this:
Whenever you init your page, call DataBind for the GridView only if you haven't set the DataSourceID, and always wrap it with "If Not IsPostBack".
If you add/change your record via a DetailsView that is bound to the same DataSource, you don't have to call DataBind on postback, since the DataSource will notify the GridView of the change.
If you add/change your record via some other means, call DataBind after it has been changed.
Here's my stack trace for Google:
[ArgumentException: Item has already been added. Key in dictionary: 'ID' Key being added: 'ID']
System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) +2904181
System.Collections.Hashtable.Add(Object key, Object value) +11
System.Collections.Specialized.OrderedDictionary.Add(Object key, Object value) +49
System.Web.UI.WebControls.DataKey.LoadViewState(Object state) +88
System.Web.UI.WebControls.DataKey.System.Web.UI.IStateManager.LoadViewState(Object state) +4
System.Web.UI.WebControls.GridView.LoadDataKeysState(Object state) +310
System.Web.UI.WebControls.GridView.LoadControlState(Object savedState) +450
System.Web.UI.Control.LoadControlStateInternal(Object savedStateObj) +118
System.Web.UI.Page.LoadAllState() +212
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +109
Saturday, 26 January 2008
WAMPed up!
You know, I'm not a big fan of LAMP. Let's say, I frown when I hear something good about it, and I hide my smile when I hear something bad. OK, at least I don't write that Windows Must Die in any other forum.
Apparently the Gods decided that it's time that I become more tolerant. First I had to make an Asp.Net site with mySql. It was sort of OK until a nasty bug deleted almost all our forums, and then they began to reappear out of some sort of mySql's recycle bin. But that's a different story.
Now I have to maintain a PHP project, and I decided that, hey, let's be tolerant! PHP is a cool object oriented language now, let's give it a try!
Installing Apache was no problem at all. I ran the default page, and it said in big bold letters, "It works!". That was cool.
Installing PHP was pretty straightforward too. But it was too late, so I went to sleep.
OK, now I'm going to check if my PHP works. Starting Apache and... there are lots of message boxes saying that httpd "This application has failed to start because php_mbstring.dll was not found" and then lots of others with different dll names. The poor beast tried again and again, so the messages won't stop until I killed it mercifully.
I decided to repair the installation and switched off all the extensions. It started nice, no message boxes. But the test PHP page I tried to view still showed nothing. In fact it showed the PHP source.
Later I discovered one possible cause. As somebody suggested, my PHP page contained something like <? phpinfo() ?>. This simplified syntax, it turned out, is switched off by default, you should write <?php phpinfo() ?> instead. Correct me if I'm wrong. But now that everything works, I can't verify this.
So, what did I do? I installed one of the available WAMP packages: EasyPHP. Works like a charm.. almost. A truly Windows-oriented application, it had minimum installation options. It even didn't ask me which of the three products (Apache, PHP, mySql) I want to install! And I was quite thankful, believe me. At least I didn't have to deal with environment paths, console commands, and huge ini files.
Apparently the Gods decided that it's time that I become more tolerant. First I had to make an Asp.Net site with mySql. It was sort of OK until a nasty bug deleted almost all our forums, and then they began to reappear out of some sort of mySql's recycle bin. But that's a different story.
Now I have to maintain a PHP project, and I decided that, hey, let's be tolerant! PHP is a cool object oriented language now, let's give it a try!
Installing Apache was no problem at all. I ran the default page, and it said in big bold letters, "It works!". That was cool.
Installing PHP was pretty straightforward too. But it was too late, so I went to sleep.
OK, now I'm going to check if my PHP works. Starting Apache and... there are lots of message boxes saying that httpd "This application has failed to start because php_mbstring.dll was not found" and then lots of others with different dll names. The poor beast tried again and again, so the messages won't stop until I killed it mercifully.
I decided to repair the installation and switched off all the extensions. It started nice, no message boxes. But the test PHP page I tried to view still showed nothing. In fact it showed the PHP source.
Later I discovered one possible cause. As somebody suggested, my PHP page contained something like <? phpinfo() ?>. This simplified syntax, it turned out, is switched off by default, you should write <?php phpinfo() ?> instead. Correct me if I'm wrong. But now that everything works, I can't verify this.
So, what did I do? I installed one of the available WAMP packages: EasyPHP. Works like a charm.. almost. A truly Windows-oriented application, it had minimum installation options. It even didn't ask me which of the three products (Apache, PHP, mySql) I want to install! And I was quite thankful, believe me. At least I didn't have to deal with environment paths, console commands, and huge ini files.
Subscribe to:
Posts (Atom)