none
visual studio different view mode(design mode && source mode) , different code generated RRS feed

  • 问题

  • create a server control (similiar code like the follows)

    [ToolboxData("<{0}:WelcomeCompositeControl id=\"a1\" runat=server></{0}:WelcomeCompositeControl>")]
    public class WelcomeCompositeControl : System.Web.UI.WebControls.WebControl, INamingContainer
    {

    ...

    }

    open one aspx page , and set it at design mode , we drag the custom server control to the page

    then the control generated automaticly, the generated code as follows:

    <cc:WelcomeCompositeControl ID="a1" runat="server" />

    but when we set the aspx page at source mode , and drag the custom server control to the page ,

    the generated code as follows:

    <cc:WelcomeCompositeControl ID="WelcomeCompositeControl1" runat="server" />

    I do not know what's wrong with my code , I want the generated code should the same.

    env.

    Windows 7 64bit sp1

    Visual Studio 2010 (10.0.40219.1 SP1Rel)

    Microsoft.NET Framework Version 4.0.30319 SP1Rel

    2012年3月5日 7:42

答案

  • [ToolboxData("<{0}:WelcomeCompositeControl  runat=server></{0}:WelcomeCompositeControl>")]

    不要加入ID


    ToolboxData 的意思是    // “    指定当从 Microsoft Visual Studio 等工具中的工具箱拖动自定义控件时为它生成的默认标记。“

    2012年3月5日 16:35
    版主

全部回复

  • [ToolboxData("<{0}:WelcomeCompositeControl  runat=server></{0}:WelcomeCompositeControl>")]

    不要加入ID


    ToolboxData 的意思是    // “    指定当从 Microsoft Visual Studio 等工具中的工具箱拖动自定义控件时为它生成的默认标记。“

    2012年3月5日 16:35
    版主
  • 我的目的就是拖动到页面上的时候 自动生成指定ID的控件,现在的问题是 两种不同模式 生成的ID是不一样的
    2012年3月6日 1:01