No access to webcontrols in my codebehind file

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
7/25/2009 5:36:08 AM
Gravatar
Total Posts 4

No access to webcontrols in my codebehind file

 Hi,

I've successfully added my own module control and it integrates fine into the solution. I've noticed though that on my supporting .aspx pages, I no longer have access to the controls on the page in the C# code behind? I've tried complely staring over with a new web project but I still get the same problem.

If I simply add a new .aspx page to my project that inherits from the standard System.Web.UI.Page I have full access in my codebehind to any textboxes atc that I add to the front end .aspx page. The problem seems to be when I inherit from the MojoBasePage and add the required content placeholders to my webform.

Has anyone else experienced this problem? I've also noticed that if I declare each control at the top of my codebehind (protected Syetm.Web.UI.Webcontrol.TextBox textbox1;) I then have access to it. I don't want to have to do this though for every control I want to use. When I look at the existing MP controls the solution like Blog this problem doesn't occur. I've used the codesmith template to create both frontend content placeholders and codebehind so I'm not sure what could be causing this problem.

Many thanks
 

 

7/25/2009 6:16:29 AM
Gravatar
Total Posts 4

Re: No access to webcontrols in my codebehind file

 Ok I belive I've worked out what the problem is. My Designer file is not generating properly as the .aspx page doesn;t recognise the controls <mp:CornerRounderTop> <mp:CornerRounderBottom> and <portal:SessionKeepAliveControl>

Could someone please tell me what needs to be present reference wise or file wise for my .aspx page to recognise they controls?

7/25/2009 6:16:46 AM
Gravatar
Total Posts 18439

Re: No access to webcontrols in my codebehind file

Hi,

This is what I do.

Make sure my custom web application project references the mojoPortal.Web project to get a reference to the base page and make any other references I may need like to mojoPortal.Business, mojoPortal.Business.WebHelpers, etc

1. Add an .aspx page to my project using VS, it creates the codebehind and the designer file.

2. Generate my starter page using the Codesmith tamplate and specifying to use the mojoBasePage

3. Paste the code behind part in first.

4. Paste in the page declaration and content templates in the .aspx part.

5. Then in order to make sure the designer updates correctly, I cut out the content templates and just leave the page declaration, then I paste the content templates back in again and then if needed switch to design view to trigger the designer to update itself.

6. Put your controls inside the <asp:Content ContentPlaceHolderID="mainContent" ID="MPContent" runat="server">

dont put stuff in other placeholders, if you need to do layout do it all inside the main one.

It should work, it works for me.

Hope it helps,

Joe

7/25/2009 6:18:56 AM
Gravatar
Total Posts 18439

Re: No access to webcontrols in my codebehind file

You need to add a reference to mojoPortal.Web.Controls project in addition to mojoPortal.Web, then copy the <pages><controls> section from the mojoportal Web.config into the Web.config in your custom web project, this will help it recognize the controls. 

Hope it helps,

Joe

7/25/2009 6:57:09 AM
Gravatar
Total Posts 4

Re: No access to webcontrols in my codebehind file

Hi Joe,

Yes that worked great! I had all the references in my project by I forgot to add the <pages> section to the local .config

Many thanks again for the quick response,

James 

You must sign in to post in the forums. This thread is closed to new posts.