Stuart Evans

This week I will be mostly using............

  Home  |   Contact  |   Syndication    |   Login
  4 Posts | 0 Stories | 31 Comments | 25 Trackbacks

News

Archives

Post Categories

BizTalk 2004

Solution Providers

My customer has a requiirement for simple wizard style (ie Next>>Next) navigation

Typical Example would be to enter details for a purchase order header, then to press "Next" and the user is taken immediately to the window for adding lines.

Investigation

I found number of ways to manipulate the navigation options of a SharePoint edit form page these being:

1) You can add a source querystring parameter to the url of the first page. This allows you to enter details for the header and then get routed to the child page that you specify in the source querystring variable as per this post.

2. You can open you NewForm.aspx , HIDE the standard list form DONT DELETE IT  (refer to http://blogs.msdn.com/dszabo/archive/2007/02/20/custom-list-newform-aspx-ruined-in-wss-3-0.aspx for details why)  insert a custom list form and remove the sharepoint:savebutton controls and replace them with form action controls. The form action controls have a number of options - these being documented here . However in my example I wanted to append the url of the redirect with a querystring property and after loads of investigation of trying to customise the navigate to page option of the form action control I gave up (the JavaScript code generates a postback to the server which controls the redirect process. The catch is that the JavaScript is generated using xslt and it beat me. Challenge anyone to get it working!)

3. You could replace the sharepoint:savebutton with a standard asp.net button and wire it up to some inline inline C#. As mentioned in my example I wanted to save the data entered and add a runtime querystring parameter to the end of the url.

So. to achieve a simpl save and redirect you can implement the following :

1. Add your inline C# code to your SharePoint page (i.e.)

<script type="text/c#" runat="server">
    void SaveAndRedirect(object sender, System.EventArgs e)
    {

//Implement your own code for creating the url
  string redirectUrl ="http://vsmoss?paramName=12345";
  SPContext.GetContext(this.Context).Item.Update();
  Response.Redirect(redirectUrl  );
    }
</script>

2. Add PageParserPath entry to your web.config. You will need to modify the virtual path to reflect the name and url of your custom page.

<PageParserPaths>  
<PageParserPath VirtualPath="/Services/Lists/Calendar/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>

3. Add your asp.net button to your page.

 <asp:Button runat="server" Text="Button" id="Button1" OnClick="SaveAndRedirect"/>

You will need to restart IIS for the changes to take effect.

This technique is an extension to a post from Nick Swan who discusses inlining C# in master pages but isn’t too keen on thee idea. I'm open to suggestions as to whether standard aspx pages are candidates for this type of modification.

Conclusion

If you need simple navigation logic then this technique works. Of course there is more than likely a slicker solution that I haven’t thought of . I guess the most likely solution would be to create a SharePoint form control that inherits from one if the controls in the Microsoft.Sharepoint.WebControls namespace. I attempted this and managed to get it rendering in SPD but kept getting runtime errors that I couldn’t get to the bottom of. If anyone has implemented a custom SharePoint form button I'd love to find out how they got it working.

posted on Monday, May 14, 2007 10:38 AM

Feedback

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 6/17/2007 10:55 AM Andrew Sapp
Great post and that works great.

However, after racking my brain on this same problem-I did solve it with a Sharepoint button.

Put a paramater in for your querystring into the ParameterBinding section of the webpart:
<ParameterBinding Name="CaseId" Location="QueryString(CaseID)" DefaultValue="0"/>

Then in the XLST add your parameter to the XLST and also your redirect location:
<xsl:param name="CaseId" />
<xsl:variable name="RedirectLoc">/Lists/Cases/ContactNewForm.aspx?CaseID=<xsl:value-of select="$CaseId"/></xsl:variable>

And then your button in the custom form:
<input type="button" value="Save" name="btnTopSave" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={',$RedirectLoc,'}'))}"/>

Regards,
Andy


# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 7/13/2007 12:37 AM bernadet
Hi,

I tried this solution but am getting an unexpected error when executing "SPContext.GetContext(this.Context).Item.Update();".

I am trying this on a new form page.

anyone can help me pls?

Regards,
bernadet

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 7/19/2007 2:29 AM inspire
Thank you so much-I've been struggling with how to get my edit form to redirect on and off for the last week.

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 8/31/2007 1:24 AM Chetankumar Patel
I tried this solution using Sharepoint Designer. I have two problem.

1. My ListFromWebPart have Title as required field. If I hide this, how do I fill the value programmaticaly or set attribute not be required on post.
2. My c# function is not getting called when I click on button. An idea?

Thanks,
Chetankumar.

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 12/11/2007 10:45 AM Guillermo
Hi,

My c# function is not being called either. Any help will be appreciated.

TIA
Guillermo

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 1/27/2008 6:59 PM Rao
I tried this solution using Sharepoint Designer, it works for local, but not for Anonymous Users is attachments r not working, when i click on button, its asking for username and password.
any solutions.

Thanks

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 4/11/2008 12:32 AM Sharepointer
The page on which I'm trying something similar to this always gives me an error that code block are not allowed on it. What I'm trying to do is have a button for each row in a DVWP to add the item to a list called "MyFavorites".

Any idea what the best way would be to do this?

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 7/24/2008 7:57 AM NHandberry
Did any of you ever figure out why the code didn't execute when you clicked the button? I'm running into the same problem where it basically just refreshes the screen on my EditForm.

I know my page parser path seems to be working because if I take that out I get the error Code blocks are not allowed. I've done an iisreset multiple times, but nothing is happening. No save and no redirect.

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 7/31/2008 4:06 AM NHandberry
I'm just posting back because I finally figured out why my code wasn't executing. It matters where you put your buttons. I was trying to put them basically the same place where the OK and Cancel were. You have to put the buttons outside the webpartzone.

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C# 8/2/2008 12:00 PM Deborah French

Add the code below
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

in the newform.aspx page

<!-- dkf code modified to redirect page -->
<script type="text/javascript" language="javascript">
function PreSaveAction() {
var srcUrl=GetSource();
var newSrcUrl = "http://www.your newsite.com/CU/Pages/default.aspx";
var i = aspnetForm.action.lastIndexOf(srcUrl);
aspnetForm.action = aspnetForm.action.substring(0,i) + newSrcUrl ;
return true;
}
</script>
<!-- dkf code modified to redirect page end -->

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 4 and 4 and type the answer here: