.FormCreated event firing twice?

6 posts, 1 answers
  1. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 16 Aug 2010 Link to this post

    I understand the .FormCreated event firing when a new appointment is being created, but I was a little surprised to find that it was also firing when the Cancel button was clicked?   I can live with the double execution of the event if I could sense that the cancel button has been clicked.  I looked into using the .FormCreating event but I couldn't get the control over the appointments objects I needed.
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 19 Aug 2010 Link to this post

    Hello Steve,

    The FormCreated event will be indeed raised twice on postback. This is done in order to give you a chance to recreate any dynamically added controls. Otherwise they won't be able to fire events of their own.

    If you need to know if the 'cancel' button was clicked, you can handle either of the following events:

    protected void RadScheduler1_AppointmentCommand(object sender, AppointmentCommandEventArgs e)
       {
           if (e.CommandName == "Cancel")
               Response.Write("Cancel button was clicked.");
       }
       protected void RadScheduler1_AppointmentCancelingEdit(object sender, AppointmentCancelingEditEventArgs e)
       {
           Response.Write("Cancel button was clicked.");
       }


    Greetings
    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 20 Aug 2010 Link to this post

    That's great and all, but since they fire after the .FormCreated event that doesn't do me any good.  My question was how to detect that the cancel button was used in the .FormCreated event?
  5. Answer
    Peter
    Admin
    Peter avatar
    6637 posts

    Posted 24 Aug 2010 Link to this post

    Hi SSirica,

    Here is a jQuery workaround using a hidden field as a flag to keep track of which button has been clicked.

    <script type="text/javascript">
      function pageLoad() {
          var $ = $telerik.$;
          $(".rsAdvEditCancel").bind("click", function (e) {
              document.getElementById("commandFlag").value = "cancelClicked";
          });
          $(".rsAdvEditSave").bind("click", function (e) {
              document.getElementById("commandFlag").value = "saveClicked";
           });
            
      }
      </script>
      
      <asp:HiddenField ID="commandFlag" runat="server" />


    protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
       {
           if (commandFlag.Value == "cancelClicked")
           {
               Response.Write("The cancel button has been clicked.");
               //reset the flag
               commandFlag.Value = null;
           }
           else if (commandFlag.Value == "saveClicked")
           {
               Response.Write("The save button has been clicked.");
               //reset the flag
               commandFlag.Value = null;
           }
       }


    All the best,
    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 25 Aug 2010 Link to this post

    It's a bit of a kluge, but I guess it will have to do.
  7. rakesh gudapati
    rakesh gudapati avatar
    1 posts
    Member since:
    Apr 2010

    Posted 14 Dec 2010 Link to this post

    Hi Steve,
    Is there a possibility to distinguish the 2 times calling of FormCreated event.
    for example let us consider the following events.

    Insert
    1.AdvancedInitInsert(suggested): - which indicated the form before any command event,i.e insert,Update,Delete
     2. AdavancedInsert(existed):-whic indicates the form after command event,i.e insert,Update,Delete.

    Edit
    1.AdvancedInitEdit(suggested)
     2.AdvacedEdit(existed)

    similarly for Insert and Edit?

    Thanks
    Rakesh

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017