c# - Unable to access user control public properties from generic handler -


following generic handler's code. code compiles , converts user control named navigationmenu.ascx html , sends calling page:

<%@ webhandler language="c#" class="getmenu" %>  using system; using system.web; using system.web.script.serialization;   public class getmenu : ihttphandler {  public void processrequest(httpcontext context) {     //--some other code     string markup = getusercontrolmarkup(0);     context.response.write(markup); } public string getusercontrolmarkup(int menutype) {     system.io.stringwriter writer = new system.io.stringwriter();      using (system.web.ui.page page = new system.web.ui.page())     {         system.web.ui.usercontrol usercontrol = null;         usercontrol = (system.web.ui.usercontrol)page.loadcontrol("~/user controls/navigationmenu.ascx");          type type = usercontrol.gettype();         page.controls.add(usercontrol);         httpcontext.current.server.execute(page, writer, false);         return writer.tostring();     } }  public bool isreusable {         {         return false;     } }  } 

this design code user control:

<%@ control language="c#" autoeventwireup="true" codefile="navigationmenu.ascx.cs" inherits="nm.user_controls_navigationmenu"  %> <!--some html --> 

and following cs code:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols;  namespace nm {     public partial class user_controls_navigationmenu : system.web.ui.usercontrol     {         public int menutype = -1;         public int selecteditem = -1;         protected void page_load(object sender, eventargs e)         {             //some code         }     } } 

now want access menutype , selecteditem generic handler. tried accessing them this:

((nm.user_controls_navigationmenu)usercontrol).menutype=0; 

but visual studio unable find nm namespace. tried adding generic handler class in nm namespace still same problem persists. please tell me how solve this?

finally solved myself. converted project web application right clicking project in solution explorer , selecting "convert web application". , worked. :)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -