Hi all,
It has been a while since I have written my last post. Right now, I'm in between exams but I had to take some brake in order to write my second post regarding the link options of data views.
In my last post I have written about changing the "Delete" link in the data view in a way that the user will be prompted before he deletes the item. In this post I will explain 2 way to change the "Insert" links.
Before I'll start it is important to mention that I have changed the links from text to jpg icons. This is how its looks now:

<a href="BLOCKED SCRIPT {ddwrt:GenFireServerEvent(concat('__cancel;__delete={',$KeyField,'=',$KeyValue,'};__commit'))}" onclick="return DeleteItemConfirmation();"><img src="../PublishingImages/Delete.gif" border="0"></img></a>
How to…
Replace each "BLOCKED SCRIPT" to
.
I didn't like the way the insert link allows the user add new items. Personally, I prefer the default NewItem.aspx.
The original insert link is like that:
<a href="BLOCKED SCRIPT {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">insert</a>
And we have 2 options to change it:
Option 1: Change the insert link to NewForm.aspx
That means that instead of the JS we will write the full path to NewForm.aspx. In addition we need to add 2 parameters to this link: "CancelSource" & "Source". In my testing I have noticed that you need to place the CanacelSource parameter first. Also, notice that the & should be replaced with & .
This is how the link looks like after our changes
If you don't insert these parameters you will notice the following problems:
- Source – When the user will click OK button he will be redirected to AllItems.aspx (or any other default view you have defined).
- CancelSource – If the user will click Cancel button in the NewForm.aspx he will get the following prompted (Invalid page URL) and then will be redirected to AllItems.aspx (or any other default view you have defined).
Option 2: insert another JS function to the link <!--My Favorite option -- >
We will use the IE Developer Toolbar for this. Steps:
Go to AllItems.aspx and open the IE developer tool. In the IE tool click: File>Select Element by Click.
Select the New button (1), Find the td with class named ms-splitbuttontext (2). Then copy the onclick attribute content (3), it should be somthing like that:
BLOCKED SCRIPTNewItem('\u002fLists\u002fContacts\u002fNewForm.aspx?RootFolder=\u00252FLists\u00252FContacts')
Change the link in the data view to the following:
<a href="#" onclick="BLOCKED SCRIPTNewItem('\u002fLists\u002fContacts\u002fNewForm.aspx?RootFolder=\u00252FLists\u00252FContacts')"><img src="../PublishingImages/New.gif" border="0"></img>Add new</a>
I like this way better because you don't need to insert the full path of you NewForm.aspx. This link will lead the user to your page. When he will click OK or Cancel he will be redirected back to your pages.
In my next and final post i will talk about the "edit" link.
I hope this post is helpful.
Inbar