C#: How do I execute a method on a property that has an attached event handler (without a stack overflow)
Setup: I have attached an event handler on the WebBrowser control something like this...
ChatInputElement.AttachEventHandler("onpropertychange", OnInputChange);
That part works perfect... But the site I'm messing with inputs URLEncoded information into the Input area sometime, which lacks a good human readable experience.
So I was trying to take advantage of the "onpropertychange" event, to fire a method that would URLDecode the data in the input box. Unfortunately this cau开发者_JAVA百科ses a Stack Overflow due to the "onpropertychange" event getting fired when I decode the URL...
Question: How can I accomplish URLDecoding the data in the input box, without causing a Stack Overflow? Is there a way to detect URLEncoded material, because the input box does contain data that doesn't need to be decoded at times.
You can set a class-level flag inside your handler, then exit the handler if the flag is set.
Store the result for comparison in subsequent handler-invocations:
One way to prevent the loop is to store your decoded URL in a field variable before setting the property. Then, set the property. On the second invocation of the event handler, compare the stored field with the current value of the property. If it's the same, you know that you already URLDecoded it, and you exit the event handler without modifying the property.
精彩评论