Could anybody please explain to me why my TextChanged event doesn't fire?

protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                Value.TextChanged += new EventHandler(OnValueChanged);
            }
        }


protected void OnValueChanged(object sender, EventArgs e)
        {
            ViewState["IsModified"] = true;
        }

The Value textbox is on the second page of a wizard control. AutoPostBack for Value is set to true.


I just don't get what causes it.


Thank you very much,


Dmitriy

Recommended Answers

All 5 Replies

Please use

tags in the future when pasting your code.

When the page is recreated after the postback you are not wiring up the event so the application has no knowledge that an event is associated with that textbox. Reassign the delegage when the page posts back:

[code=c#]
protected new void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
Value.TextChanged += new EventHandler(OnValueChanged);
}

Thank you sknake,

I change the code like this:

protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            Value.TextChanged += new EventHandler(OnValueChanged);

            if (!IsPostBack)
            {
...
            }
        }

But it the event still does not fire. :(

I even tried to wire up in overridden OnInit()... with the same result.


Dmitriy

It does work in a stock setup. I noticed you're overriding the page load with a new operator and the fact you're creating events in code make me think you're doing a lot of weird calls in this app.

Can you post a sample project? What ever is causing this bug is outside of the code you posted.

I don't know why it didn't work before... Suddenly it started working now. Thank you so much for your help.

Must have been a recompilation after you changed the postback code :P

Please mark this thread as solved if your question has been answered and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.