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

OnNextButtonClick event does not fire if another event fires

7 Answers 197 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Iron
Andy asked on 22 Oct 2015, 07:28 AM

I have a RadWizard with the steps created dynamically in the OnInit function ( IsPostback = false )

I have a server OnNextButtonClick event set.

 On the dynamically created step I have a RadTextBox with an ClientEvents.OnValueChanged event set

If I enter data on the RadTextBox and tab off it the OnValueChanged fires correctly

If I click the 'Next' button the OnNextButtonClick fires correctly

 However...

If I enter data in the RadTextBox and click the 'Next' button without leaving the RadTextBox the OnValueChanged event fires but the OnNextButtonClick event does not fire.

 

How do I get both events to fire when the 'Next' button is clicked?

 

7 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 26 Oct 2015, 03:04 PM
Hello Andy,

I am afraid I was not able to reproduce the behavior you have observed. Here's a short video showing how both events (the TextBox' OnValueChanged and the Wizard's OnNextButtonClick) fire after clicking on the "Next" button.
You can find attached the sample page used to test the scenario. Please run it at your end and try to reproduce the issue with it.

Regards,
Ivan Danchev
Telerik
0
Andy
Top achievements
Rank 1
answered on 27 Nov 2015, 07:53 AM

Your example works.  

 However I attached one that matches my code that doesn't work.

In my case there are 2 controls... both with an event attached that sets the value of the other control

If you type in a value in the Drop textbox... leave focus on the textbox... and click the next button.

The Drop event fires which updates the Prediction textbox... but the Next event does not fire.

The attached file is actually a zip containing my test.cs and test.aspx

0
Ivan Danchev
Telerik team
answered on 01 Dec 2015, 03:02 PM
Hello Andy,

I am not able to download the attached file. Could you please try re-uploading or copy/paste the markup and code behind directly in your post?

Regards,
Ivan Danchev
Telerik
0
Andy
Top achievements
Rank 1
Iron
answered on 02 Dec 2015, 07:57 AM

You have to right click on it... 'save link as'... rename it to remove the '.jpg'.

 however... there is the code.

 The aspx is simple.  Just a:

    <telerik:RadWizard runat="server" ID="RadWizard1" OnNextButtonClick="RadWizard1_NextButtonClick" OnWizardStepCreated="RadWizard1_WizardStepCreated">

    </telerik:RadWizard>

the code behind:

 

protected void Page_Init(object sender, EventArgs e)
        {
        RadWizardStep step = new RadWizardStep();
        step.ID = "Step1";
        step.Title = "Step1";
        RadWizardStep step2 = new RadWizardStep();
        step2.ID = "Step2";
        step2.Title = "Step2";
 
 
 
        RadWizard1.WizardSteps.Add(step);
        RadWizard1.WizardSteps.Add(step2);
        }
     protected void RadWizard1_NextButtonClick(object sender, Telerik.Web.UI.WizardEventArgs e)
        {
 
        }
 
     protected void RadWizard1_WizardStepCreated(object sender, WizardStepCreatedEventArgs e)
        {
        if (e.RadWizardStep.Index != 0)
           return;
 
        RadTextBox rcbDrop = new RadTextBox();
        rcbDrop.LabelWidth = Unit.Pixel(75);
        rcbDrop.Width = Unit.Pixel(150);
        rcbDrop.Label = "% Drop";
        rcbDrop.AutoPostBack = true;
        rcbDrop.TextChanged += rcbDrop_TextChanged;
        rcbDrop.ID = "drop";
        e.RadWizardStep.Controls.Add(rcbDrop);
 
        e.RadWizardStep.Controls.Add(new Literal() { Text = "<br /><br />" });
 
        RadNumericTextBox rcbPrediction = new RadNumericTextBox();
        rcbPrediction.LabelWidth = Unit.Pixel(75);
        rcbPrediction.Width = Unit.Pixel(150);
        rcbPrediction.Label = "Prediction";
        rcbPrediction.AutoPostBack = true;
        rcbPrediction.TextChanged += rcbPrediction_TextChanged;
        rcbPrediction.ID = "Prediction";
        rcbPrediction.NumberFormat.DecimalDigits = 2;
        rcbPrediction.DbValue = 0.0;
        e.RadWizardStep.Controls.Add(rcbPrediction);
        }
 
     private double CalculateDrop(double Prediction, double LastWeek)
        {
        return Math.Round(-1.0 * (100.0 - (((double)Prediction / (double)LastWeek) * 100.0)), 2);
        }
     protected void rcbPrediction_TextChanged(object sender, EventArgs e)
        {
        RadNumericTextBox rcbPrediction = (RadNumericTextBox)sender;
 
 
        double Prediction = Convert.ToDouble(rcbPrediction.DbValue);
 
 
        if (Prediction > 0.0)
           {
           RadWizardStep step = (RadWizardStep)rcbPrediction.Parent;
           RadTextBox rcbDrop = (RadTextBox)step.FindControl("drop");
 
           rcbDrop.Text = CalculateDrop((double)Prediction, LastWeekVal).ToString();
           }
        }
     protected void rcbDrop_TextChanged(object sender, EventArgs e)
        {
        RadTextBox rcbDrop = (RadTextBox)sender;
 
 
        double newValue = Convert.ToDouble(rcbDrop.Text);
        double drop = Math.Round(LastWeekVal * (newValue / 100.0), 2);
        double Prediction = LastWeekVal + drop;
 
        RadWizardStep step = (RadWizardStep)rcbDrop.Parent;
        RadNumericTextBox rcbPrediction = (RadNumericTextBox)step.FindControl("Prediction");
        rcbPrediction.DbValue = Prediction;
        }
0
Ivan Danchev
Telerik team
answered on 04 Dec 2015, 04:12 PM
Hello Andy,

For some reason I skipped the last line of your post with the extra details on the attached file.

I tested the sample page and was able to locate the problem, which is related to initiating the postback after blurring the "drop" TextBox. prior to the "Next" button click being intercepted by the browser. It seems it is browser behavior (IE), because in Chrome both events are firing correctly.
To make both TextChanged and NextButtonClick fire in all browsers I can suggest setting the "drop" TextBox' AutoPostBack property to "false":
protected void RadWizard1_WizardStepCreated(object sender, WizardStepCreatedEventArgs e)
{
    if (e.RadWizardStep.Index != 0)
        return;
 
    RadTextBox rcbDrop = new RadTextBox();
    rcbDrop.LabelWidth = Unit.Pixel(75);
    rcbDrop.Width = Unit.Pixel(150);
    rcbDrop.Label = "% Drop";
    rcbDrop.AutoPostBack = false;
    //...
}

To keep the TextBox initiating postback on blurring you can do it manually in the OnValueChanged client-side handler (we subscribe the "drop" TextBox to this event in the WizardStepCreated handler). I am reattaching the sample page to demonstrate this approach.

Regards,
Ivan Danchev
Telerik
0
Andy
Top achievements
Rank 1
Iron
answered on 05 Dec 2015, 07:12 PM

[quote]Ivan Danchev said:Hello Andy,

To keep the TextBox initiating postback on blurring you can do it manually in the OnValueChanged client-side handler (we subscribe the "drop" TextBox to this event in the WizardStepCreated handler). I am reattaching the sample page to demonstrate this approach.

Regards,
Ivan Danchev
Telerik
[/quote]

This worked but the delayed full page post was kind of irritating.

I wouldn't mind losing events if the one I got was the 'Next'

BTW... I'm getting this on chrome also... not just IE

 

0
Ivan Danchev
Telerik team
answered on 09 Dec 2015, 05:55 PM
Hello Andy,

We haven't found a different workaround, but if the delay is too noticeable you could reduce the timeout time:
timeout = setTimeout(function () {
    __doPostBack();
}, 80);

This makes the delay barely noticeable at my end.

The other way (removing the code that does manual postback while keeping the TextBox' AutoPostBack property to "false" is less user friendly and the Prediction TextBox will not get updated until you hit Next.

Regards,
Ivan Danchev
Telerik
Tags
Wizard
Asked by
Andy
Top achievements
Rank 1
Iron
Answers by
Ivan Danchev
Telerik team
Andy
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Iron
Share this question
or