Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OnTextChanged method does not fire
Message
From
29/12/2008 16:24:42
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01369966
Message ID:
01370001
Views:
16
>>>>>Hi,
>>>>>
>>>>>I have added code in the PAGE_LOAD method of the page to have a textbox post back and to fire method on change. The code is as following:
>>>>>
>>>>>
>>>>>MyTextBox.Attributes.Add("OnTextChanged", "MyTextBox_TextChanged()");
>>>>>MyTextBox.AutoPostBack = true;
>>>>>
>>>>>
>>>>>The page does post back when the entry in the text box MyTextBox changes but the method MyTextBox_TextChanged never fires. Can you see what maybe missing in my code?
>>>>>
>>>>>Thank you in advance for any help.
>>>>
>>>>Why not just use:
MyTextBox.TextChanged += new EventHandler(MyTextBox_TextChanged);
instead....
>>>
>>>I did try this approach but still it didn't work. I think the only way for me to do what I am trying to do is to add the call to this method in the .ASPX side. That is, specifying the method in the code behind does not work.
>>>Thank you for your suggestion.
>>
>>Suggestion works for me. Can you post all of your relevant .cs file content?
>
>My code looks almost exactly as I posted here (except for the names). I have in the PAGE_LOAD method the following code:
>
>
>txtCostCenter.TextChanged += new EventHandler(txtCostCenter_TextChanged);
>
>
>The debugger does indicate that code goes through this line.
>
>Then I have this method:
>
>
>public void txtCostCenter_TextChanged(object sender, System.EventArgs e)
>
>
>But if I set the debugger on this method it never fires. However, if I specify this method in the .aspx side as:
>
>
>OnTextChanged="txtCostCenter_TextChanged"
>
>
>the method fires.
>
>I think the issue is maybe where (in PAGE_LOAD) I am adding this code. Could it be?

Page.Load should be fine. This is my test C# code:
namespace NotImportant
{
    public partial class Testing : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox1.AutoPostBack = true;
            TextBox1.TextChanged += new EventHandler(TextBox1_TextChanged);
        }

        void TextBox1_TextChanged(object sender, EventArgs e)
        {
            System.Diagnostics.Debugger.Break();
        }
    }
}
The eventhandler fires as expected - not sure what is different in your case......
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform