locked
Cancel Button Redirect RRS feed

  • Question

  • Hey Everyone,

    I have looked around for this, but have been unable to find an elegant and easy solution. Is there a way to redirect a cancel button on a newform.aspx page without a lot of hassle. I would like to be able to do it through a CEWP. No custom forms, no SharePoint Designer. An alternative acceptable solution would be to hide the button using JavaScript and insert a "Cancel" text link.

    Does anyone have a good solution for this?

    I would appreciate the help.

    Thursday, April 15, 2010 1:17 PM

Answers

  • The button will look something like this:

    <input name="ctl00$m$g_e845e690_00da_428f_afbd_fbe804787763$ctl00$toolBarTbltop$RightRptControls$ctl02$ctl00$diidIOGoBack" class="ms-ButtonHeightWidth" id="ctl00_m_g_e845e690_00da_428f_afbd_fbe804787763_ctl00_toolBarTbltop_RightRptControls_ctl02_ctl00_diidIOGoBack" accessKey="C" onclick="STSNavigate('http:\u002f\u002fwww.sympraxisconsulting.com\u002fIntranet\u002fJQueryLib\u002fLists\u002fSales Opportunities\u002fAllItems.aspx');return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$m$g_e845e690_00da_428f_afbd_fbe804787763$ctl00$toolBarTbltop$RightRptControls$ctl02$ctl00$diidIOGoBack", "", true, "", "", false, true))" type="button" target="_self" lpcachedvisval="1" lpcachedvistime="1271360155" value="Cancel"/>

    so you can do something like this with jQuery:

    <script language="javascript" type="text/javascript" src="/jQuery Libraries/jquery-1.4.2.min.js"></script><script language="javascript" type="text/javascript">$(document).ready(function() { // This will unbind the existing click event $("button[Value='Cancel']").unbind("click'"); // Then bind your own $("button[Value='Cancel']").bind("click", function() {  alert("User clicked on Cancel"); });});</script>

    M.


    Marc D Anderson - Sympraxis Consulting LLC -Marc D Anderson's Blog -@sympmarc -jQuery Library for SharePoint Web Services

    • Marked as answer by jburr827 Friday, April 16, 2010 12:59 PM
    Thursday, April 15, 2010 7:39 PM

All replies

  • You could use jQuery (or JavaScript) in your CEWP to remove the existing click event and add your own.

    M.


    Marc D Anderson - Sympraxis Consulting LLC -Marc D Anderson's Blog - @sympmarc - jQuery Library for SharePoint Web Services
    Thursday, April 15, 2010 1:41 PM
  • I suggest you to write a custom javascript in your master page so as to detect when the newform.aspx is being navigated and there you can whatever you want with the cancel button.
    Thursday, April 15, 2010 5:45 PM
  • Does anyone have an example or function of this being put to use? I can write it myself, but if someone already has a function, I would rather just use that then re-create the wheel.

    Thanks.

    Thursday, April 15, 2010 7:05 PM
  • The button will look something like this:

    <input name="ctl00$m$g_e845e690_00da_428f_afbd_fbe804787763$ctl00$toolBarTbltop$RightRptControls$ctl02$ctl00$diidIOGoBack" class="ms-ButtonHeightWidth" id="ctl00_m_g_e845e690_00da_428f_afbd_fbe804787763_ctl00_toolBarTbltop_RightRptControls_ctl02_ctl00_diidIOGoBack" accessKey="C" onclick="STSNavigate('http:\u002f\u002fwww.sympraxisconsulting.com\u002fIntranet\u002fJQueryLib\u002fLists\u002fSales Opportunities\u002fAllItems.aspx');return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$m$g_e845e690_00da_428f_afbd_fbe804787763$ctl00$toolBarTbltop$RightRptControls$ctl02$ctl00$diidIOGoBack", "", true, "", "", false, true))" type="button" target="_self" lpcachedvisval="1" lpcachedvistime="1271360155" value="Cancel"/>

    so you can do something like this with jQuery:

    <script language="javascript" type="text/javascript" src="/jQuery Libraries/jquery-1.4.2.min.js"></script><script language="javascript" type="text/javascript">$(document).ready(function() { // This will unbind the existing click event $("button[Value='Cancel']").unbind("click'"); // Then bind your own $("button[Value='Cancel']").bind("click", function() {  alert("User clicked on Cancel"); });});</script>

    M.


    Marc D Anderson - Sympraxis Consulting LLC -Marc D Anderson's Blog -@sympmarc -jQuery Library for SharePoint Web Services

    • Marked as answer by jburr827 Friday, April 16, 2010 12:59 PM
    Thursday, April 15, 2010 7:39 PM