1
Answer

casting at runtime

yinghui.zeng

yinghui.zeng

21y
1.9k
1
I am trying to cast a user control at run time. Here are some code // load usercontrol, string userControlFileName="test.ascx"; Control rptCtl= LoadControl(userControlFileName); //get the type of the user control System.Type userControlType = rptCtl.GetType() // casting ((userControlType) rptCtl).setInfo(); The last line gave me compile error as follows "the type or namespace userControlType could not be found"; userControlFileName is determined at runtime, so the type of the user control has to be determined at runtime. I defined a method setInfo() in the user Control to define some class variables, in order to invoke this method, I have to cast the user control to its specific type. I have searched internet crazy and all I can find is an example that does the same thing as I did. Could anybody please help me out? Susan
Answers (1)
Next Recommended Forum