Tuesday, 20 December 2011

DropDownList has a SelectedValue which is invalid because it does not exist in the list of items

This issue is sometimes caused by changing the datasource of a drop down in the same page lifecycle.

This can be fixed by clearing the selection and selected item of the drop down list before rebinding to a new datasource.

eg:

Friday, 16 December 2011

How to load a drop down in a jqGRid with inline editing

Javascript:


aspx:

cs:

How to fire a non static code behind method from a javascript postback

I have found an interesting way of firing code behind methods from javascript functions without creating static web methods and ajax calls.

This in conjunction with an UpdatePanel produces a method that can be called from javascript that does not refresh the page.

If an update panel is used, then its a good idea to use the Id for a control inside the update panel so its marked for asyncrous postback, then differentiate between methods using the event argmument

to post back to the server using a javascript function the following code can be used:



We can then set the code behind to inspect the Request.Form collection for any postback information.

This can be very powerful as potentially any code behind method can be called!

Wednesday, 14 December 2011

How to Show a jQuery Dialog from Code behind

If you need to show a jQuery dialog from codebehind you can do so with the following code:

aspx:



js in aspx:

Note: dlg.parent().appendTo(jQuery('form:first')) is required so the dialog can be the same state after postback



code behind:

Basically we are adding a script to page load to create the dialog by calling our javascript method.

Thursday, 8 December 2011

Application pool crashes with The identity of application pool, 'your app pool' is invalid

I have had an issue with an application pool crashing with an error saying the identity of the application pool is invalid. After changing the username and password multiple times it became clear an incorrect password is not an issue.

The application pool was actually running as a local user on the web server. In order for a user account to be used in an application pool it needs to be added to a local security group (I have never done this before so its certainly not always the case).

To get it working be sure that the account is a member of the local security group "IIS_WPG", for membership in the IIS_WPG group is needed to run the w3wp.exe worker process.

Friday, 2 December 2011

Showing a modal dialog while page is updating

If you want to show a modal dialog while an update panel is updating it can be achieved with the following code:

Markup:


Javascript