none
Content Type Title on Newform.aspx RRS feed

  • Question

  • I have a Calendar created with 8 Different Content types in it which are derived from Calendar Event and List item. In the Newform.aspx based on content type ID respective fields are present.
    My Question is there a way to display Content type Name on Newform.aspx so that user's will come to If there are filling right now or not.
    Thursday, September 17, 2009 11:16 PM

Answers

  • Hi

    Actually, content type name can be displayed in EditForm.aspx and DispForm.aspx with the “content type” property of the ListItemProperty class has been specified.
    However, it is not available to display content type name in NewForm.aspx. The reason for this is that “content type” property can only be use after an item has been created.

    A workaround is to use inline-code via SPD. You can try the following steps to make it:

    1. Modify the web.config based on the reference below.
    http://weblogs.asp.net/soever/archive/2006/07/27/SharePoint-2007_3A00_-using-ASP.NET-server-side-code-in-your-pages.aspx

    2. Add a control to display your content type
    <asp:Label runat="server" ID="ctype"></asp:Label>

    3. Add code in NewForm.aspx to display content type name in your label
    <script language="C#" runat="server">
                  protected override void OnLoad(EventArgs e)
                 {
                      if (Request.QueryString["ContentTypeId"] != null)
                     {
                           string ctype=Request.QueryString["ContentTypeId"];
                           SPWeb oWeb = SPContext.Current.Web;
               
                           SPContentType type = oWeb.Lists["List"].ContentTypes[new SPContentTypeId(ctype)];
                                 
                           this.ctype.Text=type.Name;
                     }
                      base.OnLoad(e);
                  }
           </script>

    Best Regards!

    • Marked as answer by Lily Wu Friday, September 25, 2009 1:14 AM
    Thursday, September 24, 2009 6:11 AM

All replies

  • I have a Calendar created with 8 Different Content types in it which are derived from Calendar Event and List item. In the Newform.aspx based on content type ID respective fields are present.
    My Question is there a way to display Content type Name on Newform.aspx so that user's will come to If there are filling right now or not.

    Just assuming Is there any XSL Property to display it using Sharepoint designer
    • Merged by Lily Wu Friday, September 18, 2009 1:17 AM the same topic the same issue
    Thursday, September 17, 2009 11:15 PM
  • I'm not sure if I understand your question.  Doesn't NewForm.aspx display a Content Type dropdown at the top of the form?

    M.
    Marc D Anderson - Sympraxis Consulting LLC - Marc D Anderson's Blog - @sympmarc
    Friday, September 18, 2009 2:33 PM
  • I never saw Content type dropdown on top of the form. When you select a particular content type from New button(in AllItems.aspx) all the fields in that particular one will be displayed in Newform.aspx. What all I wanted is Dispaly Content type Title on Newform.aspx
    Friday, September 18, 2009 2:57 PM
  • Hi

    Actually, content type name can be displayed in EditForm.aspx and DispForm.aspx with the “content type” property of the ListItemProperty class has been specified.
    However, it is not available to display content type name in NewForm.aspx. The reason for this is that “content type” property can only be use after an item has been created.

    A workaround is to use inline-code via SPD. You can try the following steps to make it:

    1. Modify the web.config based on the reference below.
    http://weblogs.asp.net/soever/archive/2006/07/27/SharePoint-2007_3A00_-using-ASP.NET-server-side-code-in-your-pages.aspx

    2. Add a control to display your content type
    <asp:Label runat="server" ID="ctype"></asp:Label>

    3. Add code in NewForm.aspx to display content type name in your label
    <script language="C#" runat="server">
                  protected override void OnLoad(EventArgs e)
                 {
                      if (Request.QueryString["ContentTypeId"] != null)
                     {
                           string ctype=Request.QueryString["ContentTypeId"];
                           SPWeb oWeb = SPContext.Current.Web;
               
                           SPContentType type = oWeb.Lists["List"].ContentTypes[new SPContentTypeId(ctype)];
                                 
                           this.ctype.Text=type.Name;
                     }
                      base.OnLoad(e);
                  }
           </script>

    Best Regards!

    • Marked as answer by Lily Wu Friday, September 25, 2009 1:14 AM
    Thursday, September 24, 2009 6:11 AM
  • Lily Wu,

    Thank you for your help.

    Would you please let us know where the second step of your workaround should go.
    I am not sure if I should add the <asp:Label runat="server" ID="ctype"></asp:Label> to the NewForm.aspx or somewhere else.

    Thanks
    Wednesday, November 11, 2009 1:56 AM
  • Hi

    Does this work using SPS and SPD 2010?

    Thanks

    Tuesday, September 28, 2010 7:25 AM
  • I would like to ask the same question: Where should I place Step 2? And: Which path must I place in the tag inside the web.config?

    Thanks!
    Regards
    Christian

    Friday, February 25, 2011 12:13 AM