Confirmation dialog for Cancel button in sharepoint webpart - sharepoint

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.

Related

How to display busy status in Kentico custom module

I have a custom module that contains a button. The button click performs a process that sometimes takes 5-10 seconds to complete. Is there a way in Kentico to display a custom busy message like the "Loading" message that Kentico displays during lengthy processes? I would like to show the same "Loading" msg that Kentico shows with my own custom message.
If your module is built using the out of the box page templates and webparts, this is included by default. If it is not and you're using custom aspx template pages, you'll need to ensure that the page in inherited properly and add that in. You might want to reference another out of the box module which is using code already like the Users in the Membership module.
Yes, but it depends on how things are set up.
If the button executes an Ajax Panel (it does a postback through an ajax call), then you can capture the ajax call and put your loading message there.
<script type="text/javascript>
var AjaxHandler = Sys.WebForms.PageRequestManager.getInstance();
AjaxHandler.add_beginRequest(beginRequestHandler);
AjaxHandler.add_endRequest(endRequestHandler);
function beginRequestHandler(sender, args) {
// Waiting
}
function endRequestHandler(sender, args) {
// close waiting
}
</script>
If you have it postbacking on the page, you can try to put a hook when the button is clicked to show the waiting, when the page refreshes then the waiting will of course be gone.
$("#mybutton").click(function() {
// Waiting
});

Dynamic CRM 2011. Hide/show tabs using radio buttons issue

I have this code that hides tabs and shows tabs in CRM 2011. By default all tabs are hidden, but when the client has the product purchased (yes selected), the tab is showen.
The issue I am having is when I click yes and save & close. Then reopen the account, the tab is hidden, but the option is still yes.
The code is:
function showTab(tabNumber, optionField, optionValue) {
if (Xrm.Page.getAttribute(optionField).getValue() == optionValue) {
Xrm.Page.ui.tabs.get(tabNumber).setVisible(true);
}
else {
Xrm.Page.ui.tabs.get(tabNumber).setVisible(false);
}
}
The option I have is:
2,"new_server",'1'
I got the code from this place:
Show a Tab Dynamics CRM 2011
I am still working on this.
You need to register this function on both the form's OnLoad event and the field's OnChange event. It sounds, from your description, that it is registered and working for the OnChange event but the OnLoad event.
You currently have the function registered on the onChange event for the radio button control.
Additionally, you need to register an onLoad event for the form.
Create a new web resource.
Open Form Properties.
Add form to available resources.
Add event handler onLoad, and call your webresource.
In the web resource you can just have a call to your showTab function.
When you open the form for customization, look at the top ribbon of the form. You will see Form Properties icon right next to Preview. Click on Form Properties and then add the JavaScript web resource in the Form Library.
Choose Event: OnLoad from the drop down and then click add under the Event Handler.
Choose the web resource of your choice, add the function name being used in your code (showTab).
This will add the function to your Onload event of the form.

How to capture the save ribbon event for custom web part?

I have two webparts on a Project Details Page, webpart #1 is a default form webpart, webpart#2 is a custom webpart with custom form.
Now when I click on "Save" in ribbon it fires the save event for Web Part 1.
My question: Is there a way to capture the save ribbon event, so I can trigger the save event of my custom web part ?
Thank you,
We can specify the OnSaveHandler at runtime as follows,
SPContext.Current.FormContext.OnSaveHandler = btnSave_Click;
You can try to achieve this using javascript. You need to add your custom script block with function PreSaveAction.
Something like this:
<script>
function PreSaveAction(){
//Do your stuff
}
<script>
Please refer to this post.

client message after SSJS routine how?

I have a Button that in SSJS send and Email...
Now I would if is possibile show the status of sending of email in real-time to the user:
sending process....
sending Successful or sending error
How Can i call a JS client codice from SSJS routine?
Have you any suggest?
If you are using ExtLib then you can also use the #WarningMessage('messageText') method.
You will need to add a section to the XPage to display the messages. It can be as simple as
<xp:messages id="messages1"></xp:messages>
Once added each call to #WarningMessage will add a line to the messages pane.
8.5.3 introduced a very nice approach:
view.postScript
you may insert any CSJS code you like from the SSJS code.
This is quite straightforward.
1. Add a Hidden Input control on your page, noting the id.
2. In your SSJS use getComponent("inputHidden1").setValue("This is the message")
3. Ensure the Hidden Input control is in the area being refreshed (otherwise the value doesn't get passed back to the browser, so can't be accessed in CSJS)
4. Go to the Source pane and place the cursor on or in the eventHandler that is triggering your SSJS. You need to do this to get to the onComplete event
5. In All Properties panel go to onComplete, add your CSJS there. e.g. alert(dojo.byId("#{id:inputHidden1}").value)
This will run your SSJS and on completion alert the user with whatever code is in the field.
For a demo and demo code, check out my blog post: http://www.intec.co.uk/xpages-calling-client-side-javascript-from-server-side-javascript/
Another way to do it besides Pauls answer is to use a dialog from the extlib, and you can call it from ssjs, put a field in a dialog and set it to a scope value and show the dialog.

Custom action after sending Infopath form

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.

Resources