SharePoint Designer 2007 - custom submit button committing every content type to default content type - sharepoint-2007

When I submit a new item to a list with 5 content types, everything is being saved as the default content type.
Applications: SharePoint 2007 & SharePoint Designer 2007
I have a list with 5 content types. I have created Custom List Forms for each one to replace the Newform.aspx page.
I have commented out the code for the default "Save" buttons on these forms because I want them to redirect the user to a page other than the default list view upon submittal. I tried using the "Redirect URL" command on the default buttons, but it appears to have no effect on the functionality:
<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton1" RedirectUrl="http://www.destinationpageforuser.com"/>
Then I did a little internet research and swapped out the default buttons for this chunk of code:
<input type="submit" value="OK" name="btnFormActionSave1" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={http://www.destinationpageforuser.com}')}" />
This allows the redirect to happen, but causes every new item to save as the default content type.
Then I tried adding a Form Action Button from the Toolbox in Designer:
<input type="submit" value="Submit" name="Submit1" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={http://www.destinationpageforuser.com}')}" />
When I press this, it 1) causes the item to submit as the default content type, 2) clears the NewForm.aspx page of data, and 3) does not redirect but rather sits there on the now empty NewForm.aspx page blinking stupidly at me.
Do I need to pass the content type id somewhere in the button code to ensure the content type is correct? I'm not experienced enough with coding to know where this might go.
So to sum up - I need to both redirect my users to a specific page upon submittal of a new item to the list, and I need the different content type to be respected. Any insight would be appreciated.

Related

Keeping textbox value persevered in layout on page load

In the layout page I have a text box which defines the currency used in every page. I want to keep that textbox value preserved while going from one form to another form as every time form transaction happens it reloads the layout page and clears the textbox. I was looking around for a solution in which the layout page won't load on every page transaction as it is creating overhead.
The solution I found is using pjax but I believe there should be some other solution inside MVC. So I need a solution for any of the 2 parts:
1) To preserve textbox value of the layout on every page transaction OR
2) Make the layout not load on every page transaction
You can make a partial action and then call it from your views.
<input type="text" name="currency" value="#Html.Action("GetCurrentCurrency","Currency");" />

submit button behaviour in IE

I have a problem in IE. Hitting enter when the focus is on the last input control sends the focus to the "Next" button. This submits the form. So far, so good.
The code in my base class WizardController looks to see if the Next submit button is null, as follows:
protected string NextButton
{
get
{
return ControllerContext.HttpContext.Request.Params["NextButton"];Nex
}
}
However, despite the form submitting, this property returns null unless the user explicitly clicks on the button with his mouse.
This is blatantly wrong, but I have no idea why it is happening.
EDITED TO SPECIFY THE PRECISE PROBLEM:
The problem only occurs IF there is ONLY one TEXT input control in the HTML form that gets rendered to the browser.
END EDIT
Andrew
I have finally found an explanation for my problem:
It seems to be a bug in IE, whereby if there is a single text input in the rendered HTML form, then IE will not submit the form properly. The issue is described (briefly) at:
Form Submit via Enter Key when using IE
In the above link, no description is given as to why the bug occurs, or since what version of IE, so a blanket solution is better.
The workaround suggested in the article is to add a css hidden text input (with conditionals for IE):
<!--[if IE]>
<input type="text" style="display: none;" disabled="disabled" size="1" />
<![endif]-->
This worked for me, so issue solved.
The following is included to document the issue as I experienced it:
Unlike the problem described in the article, my form did submit. However, when I tried to check which button had been accessed by hitting tab or enter key, no submit button was in the HttpContext.Request.Params collection. So the behaviour I saw was slightly different.
What the above article did identify is that this behaviour is only seen WHEN there is ONLY one text input control. A single check box, for example, does not cause the problem.
I hope that this documents the problem adequately... and that MS will one day correct the bug.
A simple work around might be to use a hidden form element and depend on that rather than the button.
<input type='hidden' name='action' value='next' />
If you have multiple buttons you can always use JavaScript to change the value of the action element just before submitting.

How to post only a specific ASCX partial instead of the whole page

I've got an ASPX page rendering a search ascx page which in turn will fill a grid on the main ASPX page.
Aside that, I've also got an ascx page which uploads files, like this:
<form method="post" action="<%= Url.Action("UploadFile") %>" enctype="multipart/form-data">
<fieldset>
<input type="file" name="file" id="file" />
<%=Html.ButtonSubmit("Upload") %>
</fieldset></form>
Here's the problem: imagine I have searched for a single entry to be displayed on the grid. The grid displays this single entry and after wards, I upload a file and press the button "Upload". The whole page gets posted and the content in the grid is lost, now displaying all the results available.
What could I do to prevent this from happening, maintaining the grid state (we're not using ViewState) or otherwise not posting back the whole page but only the ascx with the file upload?
Note: I'm new to MVC.
Your partial view is rendered inside your HTML... this results in a single "static" HTML-file without the option to submit and reload only parts of it.
I can imagine two ways to solve your problem:
1) Place your upload-formular inside an HTML-iFrame... now only this iFrame will reload on submit. Problem: Communication between parent and child-frame to have the uploaded data available, depending on what kind of action you would like to have after uploading.
2) Use jQuery/AJAX to make a javascript-based submit (http://api.jquery.com/jQuery.post/) and refresh your page content dynamically with jQuery/JavaScript. This would be my prefered way but needs some more knowledge about jQuery/JavaScript.
BTW: jQuery is nearly a must-have for any asp.net mvc application ;-)
Welcome to MVC :-)

How to redirect user back to list item form when list item is edited in SharePoint 2007?

Out of the box, I've noticed the following user experience in SharePoint 2007:
User navigates to a list.
User opens list item for display.
User selects "Edit Item" link.
User changes the list item, presses Submit.
User is redirected back to list.
Is it possible to change the last step so the user is redirected back to the list item display form? If so, how is it done?
You can create a custom form by with SharePoint Designer then customize the OK Button to save and redirect to the display view.
To create custom edit form using SharePoint Designer here is a full instructions on how to do thi http://office.microsoft.com/en-ca/sharepoint-designer-help/create-a-custom-list-form-HA010119111.aspx
Once you done this then find this line on the source code of you new page
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
and append this line below
<xsl:param name="ListItemId">0</xsl:param>
"this will make the id of the current item accessible by the button"
replace both of your OK buttons
<SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton1"/>
whit this one
<input type="button" value="OK" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={dispform.aspx?id=',$ListItemId,'}'))}" />
Save and test :).
You don't necessarily have to replace your OK buttons for this one you can also add this extra button and instead of calling it OK call it something like Save and display and let the user decide what to do (just and idea)
Hope this helps!

ASP.NET MVC: add to querystring on form submit

I'm building a grid in ASP.NET MVC and I have the following issue:
Above the grid i have a column selector which lets people customize the columns being shown. This is a form with a submit button so that people can add/remove multiple columns at once without going trough multiple postbacks.
Below the grid I have paging. This is paging trough actionlinks (a href's).
alt text http://thomasstock.net/mvcget.jpg
What happens when a user add/removes columns is that the form gets submitted to http://localhost:56156/?columnsToDisplay=EmployeeId and ofcourse the grid jumps back to page 1. I'd like to keep the grid on the page the user was currently on. So I need a way to include the current querystring parameters into the form's action attribute.
The other way around too: I need a way to do the same with actionlinks. But this is less necessary as I could always replace the a href's with buttons and put them in a form. But I'd rather not do that.
I'm looking for a solution without javascript! I can do it myself in javascript, but I'd like my grid to work perfectly on javascript-disabled browsers.
Any help is appreciated.
Edit:
Oh yeah, to make it a bit harder, I'm also looking for a solution without cookies/session variables. :-)
You need to add the line below into your column selector form
<input type="hidden" name="page" value="<%=Request.QueryString["page"]%>" />

Resources