Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Why can I check some event handlers for null, some not? -


i have ugly piece of code adds event handlers. problem is, if code called multiple times, event handlers called multiple times.

to solve problem, remove event handler first , add it.

now i've seen following behaviour:

some event handlers can checked like:

if (object.event == null) {     //     // code     // } 

others of form

if (object.object.event == null) {     //     // code     // } 

i message 'object.object.event' may occur left of -= or +=. (since i'm using german version of visual studio, don't know correct translation english).

i have no idea why behaviour looks inconsequent grateful information on this.

to more specific: it's user control.

if (mycontrol.event == null) {     //     // works     // }  if (mycontrol.treeview.nodemouseclick == null) {     //     // doesn't work     // } 

slaks correct, , has linked excellent resources. here's relevant quote chris burrows' blog article:

let me take quick detour here , explain how binding of += works in c#. there 2 possibilities:

  1. either there actual + operator, such ints, , x += y binds “x = x + y” except x evaluated once. compound assignment operator; or
  2. the thing on left hand side event, , x.e += y binds “x.add_e(y)”. event accessor operator, , in fact way bind event accessor.

so have in snippet above? well, bit of detail need decide following rule field-like events in c#: outside of class or struct defines field-like event e, binding name e resolves event itself, on legal operation calling accessor; inside class or struct defines field-like event e, binding name e resolves private delegate field.

in case, when resolving mycontrol.event, you're inside mycontrol class, don't see event object; instead see actual delegate object, can compare null. when resolving mycontrol.treeview.nodemouseclick, you're outside treeview class, can't access actual delegate object; event object, cannot compared null.

if understand correctly, of wouldn't anyway, since presumably after check null, you're going try fire treeview's event it, can't do.

depending on you're trying do, subclass treeview , add internal method call protected treeview.onnodemouseclick method fire event.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -