Tuesday, May 13, 2008

user control casting of different directory

Today I face a very good problem­­ :) in asp.net user controls and I am sure most of our developers face this same problem when they havily use usercontrols in their projects.
I have two controls one has a dropdown on the change of this dropdown selection I have to notify other controls .Yes you are right I promptly go for observer pattern but in .net we have events a good replacement. So I expose this dropdown event as property.But problem is I have to know the this dropdown selected value on other events also like on grid selection.So its better to expose this dropdown selected Item as property.Above discussion have only technical complexity ,but problem you face is different.I have to cast this dropdown usercontrol in its own type but in other user control.
ui_usercontrols_common_namefinder_ascx ucCurrentnamefinder = (ui_usercontrols_common_namefinder_ascx)namefinder;
ucCurrent
namefinder.NameChange +=new EventHandler(OnNameChange);
You will get the error “you are referenceing unkown type or assembly”.so you have to specify a tag of Reference VirtualPath = "../Common/namefinder.ascx"
you have to use this tag in that control in which you want to access other controls like in my case is namefinder.ascx
Then you should also use asp as prefix of control for safe side as following.
ui_usercontrols_common_namefinder_ascx ucCurrentnamefinder = (ui_usercontrols_common_namefinder_ascx)namefinder;
ucCurrent
namefinder.NameChange +=new EventHandler(OnNameChange);

3 comments:

N Zee said...

Hey Mate, it is your Bruv!
You know who?
Nazeer!
Anyways, I was going through it! I didn't have a clear idea of what was the problem and how did you resolve it!
I think you know what I mean!

:D

Unknown said...
This comment has been removed by the author.
Unknown said...

Actually nazeer problem is I have a user control which has a fund .On changeing a fund I have to change my all controls who relevant with fund.
so I expose an event in fund usercontrol and each usercontrol which will change on fund change.I have to findout the control from Page and register this event.At that time when you casting this fund usercontrol and accessing it's properties you got error."fund not found".We have to explicitly defined a tag of virtual path in markup of user control in which you want to use fund user control. I think it will help you to understand.