7/2/10

How to create a web custom control

   The way I went about it was to add a class library to my Web Application. After that I made my class eg customGrid inherit from GridView. On the Solution Configuration I changed the setting from Debug to Release in order to get the DLL from the release folder and add the newly built control to my toolbox...

   I dragged and dropped the control on my Default.aspx and went on to built the whole prject on debug mode. That's when I got the Warning
Warning    1    Generation of designer file failed: Unknown server tag 'cc1:customGrid1'.    C:\Users\MSen\Documents\Visual Studio 2008\Projects\myGridTest2\myGridTest2\Default.aspx    16    0    myGridTest2
This warning makes one unable to access the properties and methods of the new control, trying to set its DataSourse for example, since the Default.aspx.designer.cs does not contain code for our control. Thus the way to go around this warning and become able to access the members of the control is to modify the Default.aspx.designer.cs by including the highlighted code

    public partial class _Default {
       
        /// <summary>
        /// form1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;
        protected global::customControlNamespace.CustomControlName CustomControlID;
    }
 The afore mentioned work around will make you able to access te members of the control, but the warning will still appear every time you built the project


Another way to go around it is to open IIS and
1) Go to 'Default Web Site' properties.
2) At 'Web Site' Tab click on 'Advanced..' button.
3) In 'Multiple identities for this site' list select '80:localhost' row and then click 'Edit' button.
4) Erase the 'localhost' string there and click ok.
5) Now close your solution in Visual Studio and open it again.
If IIS is not visible try
Opening Control Panel, Programs & Features, Turn Windows Features on or off, Internet Information Services and choose the IIS Management Console

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου