I have a visual web part that performs same functions as NewForm.aspx in SharePoint.

I can enter data and click save on the visual web part and it saves title field to SharePoint list.

Now I would like to replace the NewForm with visual web part. In other words when I click on new item the web part page should open.


Create a feature receiver. On activation event use below snippet to change the Page.

SPList lst = web.Lists["ListTitle"];
string newUrl = url;
var form = web.GetFile(newUrl);
if (form != null && form.Exists)
    lst.DefaultEditFormUrl = newUrl;

Also make sure to create those pages using Module and Elements.xml file.

  • I am not creating list definition etc using VS. I have just created a visual web part and inserted it on a site page. Let me know what do you mean by the above mentioned answer – Avinash Dec 30 '14 at 16:01
  • Ok if you know the Page URL then you can change the code and hardcode the URL. – Amal Hashim Dec 30 '14 at 16:03
  • So what about the pages being created using module and elements?.. – Avinash Dec 30 '14 at 16:10
  • That is the best practice. Using that technique you can create the pages and add the webpart as part of deploying the solution. No need to manually create page, add webpart etc. – Amal Hashim Dec 30 '14 at 16:12
  • Can you please specify the steps. It would be of great help. – Avinash Dec 30 '14 at 16:13

Open the list in Shareoint Designer and create a new NewForm.aspx - we need the old one in case of a problem. Then, using UI edit, delete the webpart and add yours webpart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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