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

onClick Event on Telerik Button not initially fired but postsbacks… but eventually fired after multiple clicks

7 Answers 381 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Gotcha
Top achievements
Rank 1
Gotcha asked on 22 Nov 2011, 08:29 PM
I'm having a weird issue and i'm not sure where to look or how to debug.

I have a Master Page which has the RadAjaxManager , RadLoadingPanel, RadScriptManager
I have a Parent Page A which uses the Master Page. The Parent Page has a Combo box control with 7 provinces; Each Province has a User Control ( View ). By default , the selected index is province "SK" which loads in the same page a user control View dynamically.

Below is my HTML and Code behind for the Parent Page

<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="cmbProvince">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="phPPSAControl" 
                                UpdatePanelHeight="100%" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManagerProxy>
              
<telerik:RadComboBox ID="cmbProvince" runat="server" OnSelectedIndexChanged="cmbProvince_SelectedIndexChanged"
    AutoPostBack="true">
    <Items>
        <telerik:RadComboBoxItem runat="server" Text="Quebec" Value="QC" />
        <telerik:RadComboBoxItem runat="server" Text="Ontario" Value="ON" />
        <telerik:RadComboBoxItem runat="server" Text="Saskatchewan" Value="SK" />
        <telerik:RadComboBoxItem runat="server" Text="Manitoba" Value="MB" />
        <telerik:RadComboBoxItem runat="server" Text="Yukon" Value="YT" />
        <telerik:RadComboBoxItem runat="server" Text="Nuvanut" Value="NU" />
    </Items>
</telerik:RadComboBox>            
  
<asp:PlaceHolder ID="phPPSAControl" runat="server"></asp:PlaceHolder>
  
private string _currentProvince = "";
  
protected void Page_PreInit(object sender, EventArgs e)
{
    MasterPage master = this.Master;
  
    _currentProvince = GetCurrentOperatingProvince(IsPostBack);
    cmbProvince.SelectedValue = _currentProvince;
    txtReferenceNo.Text = "TECHLOS" + DateTime.Now.ToString("MMddyyyy-HHMMss");
  
    //Reload Dynamic Control on Every Page Creation
    LoadDetailControl();
}
  
/// <summary>
/// Handles the SelectedIndexChanged event of the cmbProvince control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs"/> instance containing the event data.</param>
protected void cmbProvince_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    phPPSAControl.Controls.Clear();
    _currentProvince = e.Value;
    LoadDetailControl();
}
  
/// <summary>
/// Loads the detail control based on _currentProvince
/// </summary>
private void LoadDetailControl()
{
    UserControl ucPPSAControl = (UserControl)LoadControl(GetUserControlPath(_currentProvince));
    IPPSAView provView = ucPPSAControl as IPPSAView;
  
    ApplicationContext.TargetProvince = _currentProvince;
  
    PPSAPresenter presenter = new PPSAPresenter(provView, ApplicationContext);
    provView.AttachPresenter(presenter, cmbProvince.SelectedValue, txtReferenceNo.Text);
  
    phPPSAControl.Controls.Add(ucPPSAControl);
}
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="cmbProvince">
<UpdatedControls>
    <telerik:AjaxUpdatedControl ControlID="phPPSAControl" UpdatePanelHeight="100%" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
        
<telerik:RadComboBox ID="cmbProvince" runat="server" OnSelectedIndexChanged="cmbProvince_SelectedIndexChanged"
AutoPostBack="true">
<Items>
  <telerik:RadComboBoxItem runat="server" Text="Quebec" Value="QC" />
  <telerik:RadComboBoxItem runat="server" Text="Ontario" Value="ON" />
  <telerik:RadComboBoxItem runat="server" Text="Saskatchewan" Value="SK" />
  <telerik:RadComboBoxItem runat="server" Text="Manitoba" Value="MB" />
  <telerik:RadComboBoxItem runat="server" Text="Yukon" Value="YT" />
  <telerik:RadComboBoxItem runat="server" Text="Nuvanut" Value="NU" />
</Items>
</telerik:RadComboBox>            
  
<asp:PlaceHolder ID="phPPSAControl" runat="server"></asp:PlaceHolder>
  
  
///      And the C# Code behind  
  
private string _currentProvince = "";
  
protected void Page_PreInit(object sender, EventArgs e)
{
    MasterPage master = this.Master;
    _currentProvince = GetCurrentOperatingProvince(IsPostBack);
    cmbProvince.SelectedValue = _currentProvince;
    txtReferenceNo.Text = "TECHLOS" + DateTime.Now.ToString("MMddyyyy-HHMMss");
    //Reload Dynamic Control on Every Page Creation
    LoadDetailControl();
}
  
/// <summary>
/// Handles the SelectedIndexChanged event of the cmbProvince control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs"/> instance containing the event data.</param>
protected void cmbProvince_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    phPPSAControl.Controls.Clear();
    _currentProvince = e.Value;
    LoadDetailControl();
}
  
/// <summary>
/// Loads the detail control based on _currentProvince
/// </summary>
private void LoadDetailControl()
{
    UserControl ucPPSAControl = (UserControl)LoadControl(GetUserControlPath(_currentProvince));
    IPPSAView provView = ucPPSAControl as IPPSAView;
    ApplicationContext.TargetProvince = _currentProvince;
    PPSAPresenter presenter = new PPSAPresenter(provView, ApplicationContext);
    provView.AttachPresenter(presenter, cmbProvince.SelectedValue, txtReferenceNo.Text);
    phPPSAControl.Controls.Add(ucPPSAControl);
}

In each UC by province, it has a Search button with an OnClick Event. The first time I land on the default province, the Search button works as expected and fires the OnClick and the Event Handler Search_Click is ran.

Below is that of a typical UC for each province


<
telerik:RadButton ID="btnSearch" runat="server" Text="Search" OnClick="Search_OnClick">
</telerik:RadButton>
  
/// <summary>
/// Handles the OnClick event of the Search control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void Search_OnClick(object sender, EventArgs e)
{
    if (isValidSearchRequest())
    {
        DisplayResultsFromResponse(presenter.Search());
    }
    else
    {
        phResponse.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>Invalid Search Request</span>")));
    }
}

Now when I change the province to "ON" ( or any other province has the same behaviour), When I click on the Search Button on the newly generated UC , it only posts back without triggering the OnClick Event. Clicking Twice , does the same thing... and on the 3rd time, It does trigger the OnClick... and ran as normal!!!

The OnClick only occurs the first time I Load the first control and the minute I change the province, so a Post back to refresh the new View with a new Search Button, the latter when clicked doesn't trigger the Search_OnClick() but rather do a post back... Clicking again will post back again and finally a 3rd time, gets it to call this function ...


7 Answers, 1 is accepted

Sort by
0
Gotcha
Top achievements
Rank 1
answered on 23 Nov 2011, 04:37 PM
It turns out I only need to assign an ID to force it when I generate the Dynamic Control. I'm guessing the initial click didnt find the button from where it originated... as when it is regenerated, the id changed and hence only did a postback as opposed to the actual Event handler.

0
Accepted
Maria Ilieva
Telerik team
answered on 25 Nov 2011, 08:52 AM
Hello Gotcha,

I review the provided code however as the scenario is rather complex I cold not isolate the exact issue for the unexpected behaviour you are observing. Could you please test the disable the ajax on the page and verify if the problem still occur. Also please use some dev tool on your browser and inspect the request to verify if any errors appear during the Button click event.
I would suggest you to open a regular support ticket and send us sample runnable application which demonstrates the described behaviour. Thus we will be able to debug it locally and advise you further.

All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Denis
Top achievements
Rank 2
answered on 07 Mar 2012, 08:08 PM
Hi Maria,

I have the same issue and it is related with AJAX; because, when I disable it the button fired the click event in the code behind the first time. I think it is related that with some (rad)textboxes that I have on the page that have enable the post-back because I want to make my button a default button.
I will need some clues with this. Thanks in advance .

<telerik:RadButton ID="SearchBtn" runat="server" Text="Search" Skin="Web20" 
           onclick="SearchBtn_Click" Width="160px" 
          Icon-PrimaryIconUrl="~/Content/images/common/btn_search.png" 
          CausesValidation="False">
     </telerik:RadButton>

 protected void SearchBtn_Click(object sender, EventArgs e)
        {
          .....
            Myfunctionforget the Datasource();
            ItineraryGrid.Rebind();
        }

0
Maria Ilieva
Telerik team
answered on 12 Mar 2012, 05:06 PM
Hello Denis,

I tried to replicate the described issue locally but to no avail. Find attached a sample runnable application which works correctly on my end and the server OnClick event fires correctly of ajaxified RadButton.
Test it on your side and let me know what the difference in your case is.

Kind regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Greg
Top achievements
Rank 1
answered on 12 Mar 2012, 05:25 PM
Thanks Maria.

I got theis answer for a current ticket some I know now what is happening:

If I understand your scenario correctly, you have set the AutoPostBack property of the RadTextBox controls on your page to true in order to send an Ajax request when the Enter keyboard button is pressed during text input. This is required because there is a problem with detecting the default button of a form when a RadInput is focused in the latest release of the RadControls for ASP.NET AJAX. This issue was addressed by our developers and a fix is already available in the latest internal build. If it is possible please test it, after removing the AutoPostBack property from the RadInputs and let us know if the issue still persist.

Regards,
Slav
the Telerik team 


So I will be installing this last fix very soon.

:)
0
ABdul
Top achievements
Rank 1
answered on 15 Apr 2013, 12:42 PM
I have the same problem with Q1 2013 version.  Master has autopost back true for language selection. login button is not firing. If I branch to a different page using a hiperlink and then come back  to the login page the button works fine.  must also have some thing to do with 2008 and IIS7. Everythog was working fine on IIS6. No issues on development machine . 
0
Maria Ilieva
Telerik team
answered on 18 Apr 2013, 10:54 AM
Hi Abdul,

Could you please download the latest SP2 release and test the application with it. Let me know if the issue still exists.

All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Ajax
Asked by
Gotcha
Top achievements
Rank 1
Answers by
Gotcha
Top achievements
Rank 1
Maria Ilieva
Telerik team
Denis
Top achievements
Rank 2
Greg
Top achievements
Rank 1
ABdul
Top achievements
Rank 1
Share this question
or