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);
  }