Sharepoint Calendar

Hi ,

I used following code to set default value of "All day event" in the SP calendar to true. However, there is a postback when the checkbox is clicked/uncliked and the javascript executes again on the page load not allowing user to unclick All day event.

The code I used is below, how would I modify it to disallow postback when checkbox is unclicked.

<script type="text/javascript">

function DisableReadOnly()
{
  // find all the elements with tag Name as INPUT
  var elements=document.body.getElementsByTagName("INPUT");
  // loop through all the elements till we find an element with type text and title as name of our field

  for (index=0; index < elements.length;++index)
    {
        if(elements[index].name == "ctl00$m$g_97f958d4_996a_42cb_97ef_cbbea8a222fb$ff71$ctl00$ctl00  $AllDayEventField" )
       {
          elements[index].checked=true;

        }

     }
  }
 _spBodyOnLoadFunctionNames.push("DisableReadOnly()");</script>

Regards,

Nemanja

July 20th, 2015 6:46pm

Try using JavaScript pageLoad method and use the isInAsyncPostBack Property of the PageRequestManager object to determine whether it's a postback. 

Refer to the following post for more information

http://stackoverflow.com/questions/26978112/execute-javascript-only-on-page-load-not-postback-sharepoint

http://forums.asp.net/t/1470911.aspx?IsInAsyncPostBack+always+returning+false

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 12:42am

HI,

Thanks ...so you are saying is that I need to run the code enveloped in this function:

 function pageLoad(sender, args) {
   
if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())

{ code goes here}}?

p.s I do not want code executed on the postback :)

July 21st, 2015 2:14am

Yes, you're right.
Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 3:09am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics