Custom action after sending Infopath form - sharepoint

I'm using a browser-enabled Infopath form with Sharepoint 2010 and I want to show a modal popup or even redirect to another page after clicking on Submit, saying "Thank you... Your form has been sent...".
I can't use a View (and change to that view on submit) because the form is inside a 'tab' in the page. I mean, the page contains 5 DIVs acessible through 5 buttons.
The DIV which is open by default is the 1st one. The form is inside the 5th DIV.
After the submit action (postback) the page reloads and the 1st DIV is shown, so the user can't see the View with "Thank you...."
Any ideias on how to solve this?
Thanks in advance!
EDIT 2
I tried Andreas' solution but didn't work.
This is my "submit" button code.
public void CTRL114_5_Clicked(object sender, ClickedEventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
this.Submit();
HttpContext.Current.Response.Redirect("ThankYou.aspx");
});
} catch (Exception ex)
{
System.Console.Write(ex.toString());
}
}
When I click on Submit, nothing happens. No page redirection, no view switching, no data submitting.
Any ideas?
Thank you!

Popup's do not work with browser-enabled forms, your only possibility will be custom code. In your submit code, you can do a redirect to a static thank you page.
HttpContext.Current.Response.Redirect("ThankYou.aspx");
Edit: In your VSTA Editor, make sure you have System.Web referenced. Without an actual exception it's really hard to say what's not working. Try the following code and post the output please -
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
this.Submit();
HttpContext.Current.Response.Redirect("ThankYou.aspx");
});
}
catch(Exception ex)
{
//implement your logging logic here
}
Edit 2: Can you open the form in preview mode and debug the code? Also consider changing your logging code to something like this:
catch(Exception ex)
{
using(var writer = new StreamWriter(#"C:\log.txt",true))
writer.WriteLine("{0}\t{1}", DateTime.Now, ex.Message);
}
because Console.WriteLine does not work with InfoPath and you never get hold of the actual exception. I'm afraid without a error messsage it will be quite hard to troubleshoot your issue any further.

Another way of redirecting is using the 'Source' parameter of the query string. It is, however, only possible to redirect to pages in the same site collection as the form. E.g.
http://[site]/_layouts/FormServer.aspx?XsnLocation=/sites/[site]/formservertemplates/[form].xsn<b>&Source=/sites/[site]/pages/[page]</b>
If ThankYou.aspx is outside the current site colleciton, you can redirect to a intermediary page which redirects to ThankYou.aspx. I have heard of no other way to bypass this.

Related

Sharepoint 2010 Site Page with User Control = Blank Page

I have a problem with a site definition, it has several site pages, in those pages i need to have a top menu, so i created a user control, that draw that menu, and added it to the pages.
After deploying the solution i can create the site just fine.
In the initial phase, i have hard coded values for the menu links, and in each of the pages i could see the menu.
Now the menu it's dynamic, so i have a sharepoint list with the menu options, so i changed the code, instead of hard-coded values, i get them from a list, the code runs fine, i can check that while debugging, but in the end i get a complete blank page.
I can't interact with sharepoint data inside a user control that will be used in a site page?
I tested the control in a normal/application page and it works just fine, in both cases (hard-coded and sharepoint data).
A simple sample of the code:
protected void Page_Load(object sender, EventArgs e)
{
lblDate.Text = DateTime.Now.ToLongTimeString();
ddlData.Items.Clear();
//Option Manual - WORKS FINE
ddlData.Items.Add("Manual 1");
ddlData.Items.Add("Manual 2");
ddlData.Items.Add("Manual 3");
//Option Sharepoint Data - DOESNT WORK
SPSecurity.RunWithElevatedPrivileges(delegate () {
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.RootWeb)
{
foreach (SPList lista in web.Lists)
{
ddlData.Items.Add(lista.Title);
}
}
}
});
}
The rest of the code, it's a simple page with the reference to this user control, and the aspx code of the user control only have the declaration of this two controls.
After several tests, i came to conclusion that i have two problems:
1 - In this project for some reason, unknown to me, inside the code someone had added some code to clear the errors, that's why i had the blank page.
2 - After seeing the error, i could confirm that if i use site pages and trying to get the data with Using, when it tries to dispose the objects it throws the exception, so the solution was simple, just remove the Usings.
Thanks

(Yii2) the page that you are looking for used information.....?

my simple view file
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<?php ActiveForm::begin()?>
<?=Html::submitButton('something')?>
<?php ActiveForm::end()?
Clicked the button. After I reload the page and browser shows me
this
So how can I remove this?
This problem happen when you submit data in a form and then refresh the page
Browsers should stop this, or at least prompt if you want to resend the data,
but the best way to prevent this from happening is submit the data .. and manage the submit properly.
In you case your submit repeat the index action because you don't manage proper the action code
(all you're being made does not produce the creation of a new model to be complete so as not prroduce displaying a result.
or any other action ..
your code continues to call the same action that produces post calling for action and so on)
try adding a simple die() or a render for another view
public function actionIndex()
{
if (Yii::$app->request->post('submit')==='my_value') {
echo "Button my_value Clicked";
die(); // or render a proper view
}
return $this->render('index');
}
This is basic browser behavior. Your form is doing a POST request and obviously when you try to refresh it will ask for this. Even if you write a basic html page without yii, you will still have this.

Preserving JSF messages after a redirect

I have a JSF page (using MyFaces 2.0) that does a bit of data gathering the first time it is displayed. If it can't find some information, it is supposed to provide a message to that effect and redirect back to a different page. I've tried using the solution found here Preserving FacesMessage after redirect for presentation through <h:message> in JSF (setKeepMessages(true)) but the messages aren't displaying after the redirect. The only difference I can pick out is that I'm not using a navigation rule, I'm calling the redirect() call on the external context because this isn't occurring in a normal action.
Relevant code:
public void redirectToPageWithMessage(String inPage, String message, FacesMessage.Severity severity){
getFlash().setKeepMessages(true);
addMessage(message, severity);
try {
getFacesContext().getExternalContext().redirect(inPage);
} catch (IOException e) {
e.printStackTrace();
}
}
Unfortunately this doesn't seem to be working. The redirect happens just fine, but the < messages /> tag isn't displaying the message. Is there something different about the way redirect() happens that prevents this from working?
The code that saves the messages are executed after the phase ends (see Flash.doPostPhaseActions(FacesContext) ). So, it is expected it does not work, but maybe you can call Flash.doPostPhaseActions before the redirect. Note is not a "clean" solution, but it is possible.
I had the same problem and solve it not using ExternalContext.redirect() but to play with outcome for your actions.
That is to say, my action called by my buttons return a String (the outcome) which indicates the navigation rules to go to the next page. With that system, the messages are preserved.
JSFMessages are kept only for the processing of the actual request. A second request is made when using redirect, so the JSFMessages will be lost. The EL-Flash is a way to work around this. This example should work: http://ocpsoft.com/java/persist-and-pass-facesmessages-over-page-redirects/

Page Refresh on popup close and losing page data

I have a repeater as user control and other fields in my SharePoint site page. I need to add records to repeater with help of modal dialog. Whatever has been selected in the popup should come to repeater. Whenever I close the popup, I am able to refresh the page, but the page is losing the other fields' data and repeater too.
Am I doing something wrong?
Finally I managed this issue with dopostback using the below snippet.
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}

Confirmation dialog for Cancel button in sharepoint webpart

hi i am creating a webpart. i have a custom toolpart for my webpart. there i'll type some text. when i click save it will print in sharepointpage. when an user click cancel in webpart's toolpart i need to ask confirmation dialog and if the user selects "OK" i need to run some server side code. is it possible. Please help me on that.
In your toolpart register an onsubmit event handler (this will be called on OK/Apply/Cancel or if you do anything else that causes a postback)
protected override void OnPreRender(EventArgs e)
{
// Don't run if in SharePoint Designer
if (ParentToolPane.InCustomToolPane)
return;
// Connect to the form Submit event RenderToolPart event is too late,
// Putting this in OnLoad event causes javascript error webpart may
// be loaded for ApplyChanges but not rendered - leading to javascript error
this.Page.RegisterOnSubmitStatement("submit", "yourCustom_onSubmit();");
base.OnLoad(e);
}
Also be sure to have a javascript function yourCustom_onSubmit on your page - putting up a confirmation message and cancelling submit is up to you.
Yes you can. It's like asp.net, so you can insert a Javascript, like the sample we found at this site.

Resources