SetFocus doesnt seem to be working

I have code that creates controls dynamically and the focus goes to the last control I create. So I am doing a SetFocus, but the focus is not changing.

Whats the trick to it?

  procedure Handle_Adventure;
  begin
    THtml.Add_Hidden_Class    (idLocation);
    THtml.Add_Hidden_Class    (idDestination);
    THtml.Remove_Hidden_Class (idCategory);
    Create_Pax_Controls;
    edtVoucher_Ref.SetFocus;
  end;

Creation Code

constructor TPax.Create (AOwner : TWebForm;
                         ATotal : TFloatField);

  function Create_Edit (ANum, AField : string) : TWebEdit;
  var
    C : TWebEdit;
  begin
    C := TWebEdit.Create (FOwner);
    C.Parent := FOwner;
    C.ElementId := 'form.edt'+AField+ANum;
    Result := C;
  end;

  function Create_Combo (ANum, AField : string) : TWebComboBox;
  begin
    Result := TWebComboBox.Create (FOwner);
    Result.Parent := FOwner;
    Result.ElementId := 'form.edt'+AField+ANum;
    Result.Items.Assign (TVirtual.Weights);
    Result.OnChange := Change;
  end;

var
  I : Integer;
  S : string;
begin
  inherited Create;
  FOwner := AOwner;
  FTotal := ATotal;
  for I in TRows
  do begin
     S := IntToStr (I);
     FRows [I]._edtFName  := Create_Edit  (S, 'FName');
     FRows [I]._edtLName  := Create_Edit  (S, 'LName');
     FRows [I]._edtWeight := Create_Combo (S, 'Weight');
     FRows [I]._edtMobile := Create_Edit  (S, 'Mobile');
     FRows [I]._edtEmail  := Create_Edit  (S, 'Email');
  end;
end;

Possibly, this is because when inserting the control (i.e. underlying HTML element) in the DOM, it isn't immediately available/accessible within the same synchronous code block. Try to set the focus after some delay to ensure the underlying HTML is effectively in the DOM.

Thats what I figured too. I dont want to wait a random amount of time.

This is called in TXDataWebClient.OnLoad event.

Is there a callback/event from TWebDBEdit.Create or another event that executes after OnLoad?

Will TXDataWebDataSet.AfterOpen get called later then OnLoad above?

No, there is no relation between TXDataWebClient and TXDataWebDataset. TXDataWebDataset.AfterOpen is called after you called TXDataWebDataset.Load and the operation completes.