Wednesday, November 05, 2008

Changing ODS parameter at runtime causes double bind

changing a pagepropertyparameter value caused the ods to invalidate itself and forced a second database access
this was fixed by maintaining a local copy of a DatabaseAccess object and returning that on each subsequent property access (the first time, it's null and created from scratch)

Wednesday, October 01, 2008

Server tags reference

<% %> An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class.

<%= %> most useful for displaying single pieces of information.
CANNOT be used to assign values to properties (ie Text='<%= GetSomeText() %>' - this won't work) See here for an alternative.

<%# %> Data Binding Expression Syntax.

<%$ %> ASP.NET Expression.

<%@ %> Directive Syntax.

<%-- --%> Server-Side Comments.

Thursday, September 25, 2008

Javascript debugging

The community content on this page contains info on javascript debugging techniques

Monday, September 15, 2008

Could not load System.Web.Extensions

Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.


Solution: Download and install the Ajax library.

Friday, August 22, 2008

Failed to load viewstate

Error:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

One possibility is that the query that selects the count and the query that selects the fields are in disparity. The count query must return the number of rows that would be returned by an unlimited field query.

Thursday, August 21, 2008

The name xxx Does Not Exist in the Current Context

This post helped me to realize that when I made copies as backups of "infringements.aspx" and "infringements.aspx.cs" named "copy of infringements.aspx" etc, the "copy of infringements.aspx" still referenced "infringements.aspx.cs" and caused the compiler some confusion.

Wednesday, August 20, 2008

Sys$CultureInfo$_getAbbrMonthIndex

Sys.ParameterCountException: Parameter count mismatch.'
function Sys$CultureInfo$_getAbbrMonthIndex(value)

I got this error when I had two controls that used javascript to show a modal popup extender. The control which was named by the mpe as the TargetControlID would not cause this error, but the other control would. (Infringements.aspx/mpeNoticeConfirm)

This appears to be a problem with the Web Developer 1.1.6 plugin for firefox. On computers without that plugin, the error console does not display the error.

Tuesday, June 03, 2008

Page Lifecycle

Here's a thread that discusses how to use trace to view the page lifecycle in action.

This page shows the complete lifecyle including master page and controls

Wednesday, February 06, 2008

DropDownList selection problem

If the selected value of a dropdownlist is incorrect it may be that the databinding is occurring in the Page_Load every time instead of only when IsPostBack is false.

Wednesday, December 19, 2007

Handle ajax slider events

<script type="text/javascript">
<!--

function pageLoad(sender, e) {
var startslider = $find('startSliderBehavior');
startslider.add_valueChanged(onValueChanged);
onStartValueChanged(startslider, null);
}

function onValueChanged(sender, e) {
//sender is the startSliderBehavior object
time = sender.get_Value();
clientID = '<%= FindNestedControl(fvMain, "lblStartSlider") == null ? "" : FindNestedControl(fvMain, "lblStartSlider").ClientID %>'
if (clientID != "")
document.getElementById(clientID).innerHTML = ConvertIntToTimeString(time);
}
-->
</script>

<asp:TextBox ID="tbSliderStart" runat="server" Style="right: 0px" Text='<%# Bind("AssetReferenceMetaStart") %>' />

<asp:Label ID="lblStartSlider" runat="server" Style="font-size: 80%;" Text="00:00:00" />

<ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server" EnableHandleAnimation="true" TargetControlID="tbSliderStart" Minimum="0"Maximum="7200" BehaviorID="startSliderBehavior" />

Wednesday, October 17, 2007

FileUpload control causes 404 error

This can occur when the size of the file being uploaded is outside the proscribed limits.
From The MSDN Article:
The default size limit is 4096 KB (4 MB). You can allow larger files to be uploaded by setting the maxRequestLength attribute of the httpRuntime element. To increase the maximum allowable file size for the entire application, set the maxRequestLength attribute in the Web.config file. To increase the maximum allowable file size for a specified page, set the maxRequestLength attribute inside the location element in Web.config.

Access the return value of an ObjectDataSource Insert method

Handle the OnInserted event of the ObjectDataSource and use the ObjectDataSourceStatusEventArgs.ReturnValue property

Thursday, October 04, 2007

Session state

I set my session state timeout to 1 minute, but after a minute has elapsed without interacting with the site, I can still browse to other pages without having to log in again. What is happening?

There is another timeout that you should set in the web.config file:
<forms timeout="1"/>

There is also an issue related to IIS where processes are recycled after being idle for a set period of time. This article explains more

Wednesday, September 05, 2007

Stack Trace - Get name of current method

System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
string methodName = st.GetFrame(0).GetMethod().Name;

Saturday, January 13, 2007

Find the databse ID of a gridview row

Convert.ToUInt32(gridview.DataKeys[rowIndex].Value)

getElementById with Master Pages

When using master pages and at certain other times the names of objects on an asp page get mangled to prevent name clashes. This makes it so that any javascript that references these objects is no longer able to find the element by its original name. To work around this use the following syntax with the getElementById


document.getElementById("<%= [ObjectName].ClientID %>")

Change [ObjectName] to be the name of the object you want to find.

Wednesday, October 18, 2006

Accessing the underlying data in an ObjectDataSource object

Sometimes you need to access the underlying data object of an ObjectDataSource object. An example may be that you need to change the caption of a non-bindable label based on some field in the data. It can be done by using the OnSelected event of the ObjectDataSource. The
ObjectDataSourceStatusEventArgs parameter of that event has a property called ReturnValue which points to the data object returned by the SelectMethod of the ObjectDataSource. If the SelectMethod returns a DataSet object, look through the tables and rows of the DataSet to find the desired data.

Friday, October 13, 2006

Dictionaries and null keys

C# does not let you initialize a dictionary entry by simply assigning a value to a non-existant key in the dictionary. So instead of
  mydictionary[key] = value;    
...where "key" does not yet exist in the dictionary, it is necessary to do something like this...
  if (mydictionary.ContainsKey(key))
  {
    mydictionary[key] += value;
    //or
    mydictionary[key] = value;
  }
  else
  {
    mydictionary.Add(key, value);
  }