Geeks With Blogs
Stuart Evans This week I will be mostly using............

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 MOSS 2007 | Back to top


Comments on this post: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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
Left by Andrew Sapp on Jun 17, 2007 10:55 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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
Left by bernadet on Jul 13, 2007 12:37 AM

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

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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.
Left by Chetankumar Patel on Aug 31, 2007 1:24 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
Hi,

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

TIA
Guillermo
Left by Guillermo on Dec 11, 2007 10:45 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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
Left by Rao on Jan 27, 2008 6:59 PM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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?
Left by Sharepointer on Apr 11, 2008 12:32 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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.
Left by NHandberry on Jul 24, 2008 7:57 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
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.
Left by NHandberry on Jul 31, 2008 4:06 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...

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 -->
Left by Deborah French on Aug 02, 2008 12:00 PM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
Andrew Sapp! your solution works great.
Left by Aleem on Jul 22, 2009 9:02 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
Hi,
If we want to refrence an external assembly i,e if I want to connect to some application to get some value from that c# code. Then How can we achieve that..??
Left by Ankur Billore on Oct 07, 2009 5:50 AM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
Man you saved my bacon!!! Thanks a lot.
Left by wendell on Nov 18, 2009 10:16 PM

# re: MOSS2007: Add Custom Wizard Style Navigation To Your Sharepoint Designer Pages Using Inline C#
Requesting Gravatar...
Thank you so much. Link was really helpful. Do you know how can i add custom themes to .aspx page?
Left by Kelvin on Apr 24, 2010 9:05 PM

Your comment:
 (will show your gravatar)


Copyright © Stuart Evans | Powered by: GeeksWithBlogs.net | Join free