Showing posts with label event handler. Show all posts
Showing posts with label event handler. Show all posts

Friday, September 13, 2013

GridView Events

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx

 NameDescription
Public eventCallingDataMethodsOccurs when data methods are being called. (Inherited from DataBoundControl.)
Public eventCreatingModelDataSourceOccurs when the ModelDataSource object is being created. (Inherited from DataBoundControl.)
Public eventDataBindingOccurs when the server control binds to a data source. (Inherited from Control.)
Public eventDataBoundOccurs after the server control binds to a data source. (Inherited from BaseDataBoundControl.)
Public eventDisposedOccurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested. (Inherited from Control.)
Public eventInitOccurs when the server control is initialized, which is the first step in its lifecycle. (Inherited from Control.)
Public eventLoadOccurs when the server control is loaded into the Page object. (Inherited from Control.)
Public eventPageIndexChangedOccurs when one of the pager buttons is clicked, but after the GridView control handles the paging operation.
Public eventPageIndexChangingOccurs when one of the pager buttons is clicked, but before the GridView control handles the paging operation.
Public eventPreRenderOccurs after the Control object is loaded but prior to rendering. (Inherited from Control.)
Public eventRowCancelingEditOccurs when the Cancel button of a row in edit mode is clicked, but before the row exits edit mode.
Public eventRowCommandOccurs when a button is clicked in a GridView control.
Public eventRowCreatedOccurs when a row is created in a GridView control.
Public eventRowDataBoundOccurs when a data row is bound to data in a GridView control.
Public eventRowDeletedOccurs when a row's Delete button is clicked, but after the GridView control deletes the row.
Public eventRowDeletingOccurs when a row's Delete button is clicked, but before the GridView control deletes the row.
Public eventRowEditingOccurs when a row's Edit button is clicked, but before the GridView control enters edit mode.
Public eventRowUpdatedOccurs when a row's Update button is clicked, but after the GridView control updates the row.
Public eventRowUpdatingOccurs when a row's Update button is clicked, but before the GridView control updates the row.
Public eventSelectedIndexChangedOccurs when a row's Select button is clicked, but after the GridView control handles the select operation.
Public eventSelectedIndexChangingOccurs when a row's Select button is clicked, but before the GridView control handles the select operation.
Public eventSortedOccurs when the hyperlink to sort a column is clicked, but after the GridView control handles the sort operation.
Public eventSortingOccurs when the hyperlink to sort a column is clicked, but before the GridView control handles the sort operation.
Public eventUnloadOccurs when the server control is unloaded from memory. (Inherited from Control.)

Thursday, March 17, 2011

SharePoint's DateTimeControl.DateChanged Event BUG

Ok. So you want something to happen (e.g. update another DateTimeControl) when you change the value in the DateTimeControl.You realise that the DateTimeControl.DateChanged event could do the trick.

But NO...
Bugs I have identified:
1) The DateChanged Event does not get fired when you change the time
2) This snippet of code within the DateChangedEvent does not seem to work:
dtEnd.SelectedDate = dtStart.SelectedDate

* Bug 1 is known and so far here's the only workaround that I know (compliments to myself):
Insert a Jquery hack to "catch" the time change event:

$(document).ready(function() {
   //Hour drop down list 
   $("#ctl00_PlaceHolderMain_dtStart_dtStartDateHours").change(function() {
      var idx = $("#ctl00_PlaceHolderMain_dtStart_dtStartDateHours option").index($("option:selected"));
      if (idx < 24) idx++;
      $("#ctl00_PlaceHolderMain_dtEnd_dtEndDateHours option:eq(" + idx + ")").attr("selected", "selected");
});


//Minute drop down list
     $("#ctl00_PlaceHolderMain_dtStart_dtStartDateMinutes").change(function() {
      var idx2 = $("#ctl00_PlaceHolderMain_dtStart_dtStartDateMinutes option").index($("option:selected"));
      $("#ctl00_PlaceHolderMain_dtEnd_dtEndDateMinutes option:eq(" + idx2 + ")").attr("selected", "selected");
    });
});
The change event for the minute drop down list doesn't seem to work as yet. It is returning idx2 as -1. Will continue exploring on this.

A/N: Still not sure why it's not working, but here's another workaround:
$("#ctl00_PlaceHolderMain_dtEnd_dtEndDateMinutes").val($("#ctl00_PlaceHolderMain_dtStart_dtStartDateMinutes option:selected").val());
I realise that I don't need to get the index of the selected option as I can just replicate the values in the end date drop down.

* Bug 2 is less well-known, can't seem to find any solutions on google. Here's my current workaround (compliments to myself as well):
Add a "OnValueChangeClientScript" property to the DateTimeControl which calls "javascript:updateDates();".

function updateDates() {
$("#ctl00_PlaceHolderMain_dtEnd_dtEndDate").val($("#ctl00_PlaceHolderMain_dtStart_dtStartDate").val());
}

Tuesday, August 3, 2010

Attaching Event Receivers to Content Types

When you define a content type with a feature, you create 2 XML files as shown below:

  • Feature.xml – Use this XML file to define the metadata for the new feature. The ElementManifests element points to the location of the 2nd XML file storing all of the detailed information on the feature itself.
  • Elements.xml – Use this file to define the assembly that encapsulates the event handler, the class itself, and also a sequence number that specifies the order.

Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x0100c07095261b4f48408d60ad8654b69d68" Name="DevelopingCT" Group="Development" Description="Developing Content Type" Version="0">
<FieldRefs>
<FieldRef ID="{0c177b88-bf35-4692-8456-cc14aaabecc0}" Name="DevelopingCTField" />
</FieldRefs>
<XmlDocuments>
<XmlDocument NamespaceURI="
http://schemas.microsoft.com/sharepoint/events">
<spe:Receivers xmlns:spe="
http://schemas.microsoft.com/sharepoint/events">
<Receiver>
<Name>ItemAdded</Name>
<Type>ItemAdded</Type>
<SequenceNumber>1</SequenceNumber>
<Assembly>AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TokenNumber</Assembly>
<Class>Namespace.ClassName</Class>
<Data>
</Data>
<Filter>
</Filter>
</Receiver>
<Receiver>
<Name>ItemAdding</Name>
<Type>ItemAdding</Type>
<SequenceNumber>2</SequenceNumber>
<Assembly>AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TokenNumber</Assembly>
<Class>Namespace.ClassName</Class>
<Data>
</Data>
<Filter>
</Filter>
</Receiver>
</spe:Receivers>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>


Note: Event receivers in content types are defined in a different section of the elements file. The Receiver XmlDocument resides in the http://schemas.microsoft.com/sharepoint/events namespace.

Related post: Writing Event Receiver Class in Code

References:

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/fecdfc46-3223-4b9d-b218-29bf475b9cd6

http://stackoverflow.com/questions/561835/how-do-you-bound-an-event-receiver-to-a-specific-custom-content-type

http://www.wrox.com/WileyCDA/Section/Programming-Event-Handling-in-Windows-SharePoint-Services.id-306329.html

http://download.microsoft.com/download/b/d/4/bd45c0a8-74bc-4e3a-9735-a715b902f89c/03-EventHandlers.docx

Monday, November 23, 2009

.NET Event Handler Definition

DropDownList
DropDownList1_Init(object sender, EventArgs e)
  • Use this method to initialise the items in the drop down list
DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  • DropDownList1.SelectedValue to get selected value

RadioButtonList
RadioButtonList1_DataBound(object sender, EventArgs e)
  • Use this method to set "selected" property of radio button list items.
Button
Button1_Click(object sender, EventArgs e)

GridView
GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  • e.Row to get the row that is being bounded by data
  • e.Row.Cells to get the collection of cells inside the row
  • Note that the content has not been rendered, so use "FindControl"
GridView1_SelectedIndexChanged(object sender, EventArgs e)
  • GridView1.SelectedValue to get the selected value.
GridView1_RowUpdating(object sender, EventArgs e)
  • This method is called when grid view row is updated (useful to set the UpdateParameter values)
CustomValidator
CustomValidator1_ServerValidate(Object source, ServerValidateEventArgs e)
  • Use this method to validate form and set appropriate control properties (e.g. Visibility)