Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using the Training Fab 40 template to build a training site in MOSS 2007. I have another content type for my Course list. I want to load the NewForm.aspx based on Content Type selected. The two content types are "Classroom Training" and "Offline Training". Although the NewForm should automatically get modified based on content type, but since I have modified the NewForm.aspx, it is not loading. I even tried to change the forms from SharePoint Designer via List properties, but in-vain.

Is there a way I can redirect to separate forms via JavaScript or anything else?

share|improve this question
add comment

1 Answer 1

I have done this in 2010 using C# but not JavaScript. I assume the concept should be the same though.

To load the NewForm based on Content Type, you have to pass the content type GUID to the NewForm.aspx page.

I have a custom dropdown that lets a user select a content type from the list. I do this with the following C# code:

using (SPWeb web = SPContext.Current.Web)
{
    SPList contracts = web.Lists["Contracts"];
    SPContentTypeCollection ctColl = contracts.ContentTypes;
    StringBuilder sb = new StringBuilder();
    sb.Append("<div id='dropdown'><button id='dropdownButton'>Submit a new contract approval request</button></div><ul>");


    foreach (SPContentType ct in ctColl)
    {
        if(ct.Name != "Folder")
        {
            string ctLink = string.Format("{0}?ContentTypeID={1}", contracts.DefaultNewFormUrl, ct.Id.ToString());

            // link to the preform with destination link as query string parameter
            string preFormLink = web.Url + "/_layouts/ContractApproval/NewContractPreForm.aspx?dest=" + Server.UrlEncode(ctLink);

            //string link = string.Format("<a href='javascript:OpenModal(\"{0}\", \"Contracts - New Item\")'>{1}</a>", ctLink, ct.Name);

            string link = string.Format("<a href='{0}'>{1}</a>", preFormLink, ct.Name);

            sb.AppendFormat("<li>{0}</li>", link);
        }
    }

    sb.Append("</ul>");
    LiteralControl lc = new LiteralControl(sb.ToString());
    this.Controls.Add(lc);
}

Your URL should look something like this:

/sites/CA/Lists/Contracts/NewForm.aspx?ContentTypeID=0x0100B7E10C04703F5C40B7D4E4301CC41C0B00EA422A48FBA2D94487375C7CBB49F0CC
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.