Error displaying custom form in SharePoint

Posted: November 17, 2009 in Custom Form, Item Display Error

If you have ever tried to create a custom display form or try to redirect to a custom page from DispForm.aspx you will get an error “Item not found at ….. . It may have moved or renamed by the user.”

It’s because sharepoint by default uses the Querystring parameter with the name “ID”. And when we try to use the same name for our custom page it throws an exception.

So we have to use some other parameter name instead of “ID”. This will be easy if your custom page contains your custom webpart. But if your page contains a custom list webpart provided by default which you add through SharePoint designer, just changing the querystring parameter name will not do. Lets see how to do it.

Problem :

Say I have two views for a list and when i click an item from View1 it should take me to CustDispForm1 and for View2 it should be CustDispForm2.

Solution :

1) I have created two webpart pages(CustDispForm1, CustDispForm2) and through the designer I added the Custom List Form of  the list.

2) I created a webpart deployed on DispForm.aspx which will redirect to one of the custom page based on the page/view from which its coming. ( The view from which its coming can be found from the Querystring parameter “Source“).

3) Now in the webpart i should add a code like

if(viewName=”View1″)
{
Response.redirect(“…../CustDispForm.aspx?DisplayItemID=”+this.Page.QueryString[“ID”]);
}
else if(viewName=”View1″)
{
Response.redirect(“…../CustDispForm.aspx?DisplayItemID=”+this.Page.QueryString[“ID”]);
}

Note that here i have given the ID of the item in querystring but the parameter name is changed to “DisplayItemID”.

4) Of course the above code will redirect to my custom pages based on the different views. But if you remember our custom page contains a “Custom List Form webpart” which will display item based on the QueryString parameter with name “ID”.

5) Here comes the trick and we have to change this parameter name “ID” to our parameter name “DisplayItemID”.

6) Open the Custom display form (CustDispForm1.aspx) and find the tags

<ParameterBinding Name=”ListItemId” Location=”QueryString(ID)” DefaultValue=”0″/>

7) Replace “ID” with “DisplayItemID” in this code.

8 ) That’s all and now check your page in the browser.

Advertisements
Comments
  1. zynga says:

    im regularly roaming all across the online world nearly all of the working day therefore I choose to read a great deal, which unfortunately isn’t usually a good thing as some of the internet sites I find are composed of unnecessary rubbish copied from some other internet sites a trillion times, but I gotta give you props this website is genuinely quite informative and supplies a bit of authentic substance, therefore kudos for breaking up the trends of only duplicating other peoples’ sites, in case you ever want to try a few hands of zynga poker together with me just send me a message – you have my email address 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s