This is a migrated thread and some comments may be shown as answers.

.FormCreated event firing twice?

5 Answers 93 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
SSirica asked on 16 Aug 2010, 03:44 PM
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.

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 19 Aug 2010, 09:50 AM
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
0
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
answered on 20 Aug 2010, 02:52 PM
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?
0
Accepted
Peter
Telerik team
answered on 24 Aug 2010, 01:59 PM
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
0
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
answered on 25 Aug 2010, 05:16 PM
It's a bit of a kluge, but I guess it will have to do.
0
rakesh gudapati
Top achievements
Rank 1
answered on 14 Dec 2010, 11:10 AM
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

Tags
Scheduler
Asked by
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Peter
Telerik team
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
rakesh gudapati
Top achievements
Rank 1
Share this question
or