PDA

View Full Version : [CLOSED] Change event triggers when textfield modified in code-behind



jstifel
Nov 26, 2013, 12:40 PM
Hi there, I have setup a textfield on a form with a direct event triggering when field changes. I was expecting this event to trigger only when user changes the value manually on browser. Then I realized that if I change textfield value on code behind, the change trigger triggers the same. Is it there a way to disable trigger when textfield is modified at server side? I tried adding "return false;" to Before property of the event before assigning value but it did not work.

Daniil
Nov 26, 2013, 4:40 PM
Hi @jstifel,

Yes, the Change event fires on any change.

You can suspend the event on demand.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Set(object sender, DirectEventArgs e)
{
this.TextField1.SuspendEvent("change");
this.TextField1.Text = "test";
this.TextField1.ResumeEvent("change");
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:TextField ID="TextField1" runat="server">
<Listeners>
<Change Handler="console.log('change');" />
</Listeners>
</ext:TextField>

<ext:Button runat="server" Text="Set" OnDirectClick="Set" />
</form>
</body>
</html>

jstifel
Nov 26, 2013, 7:13 PM
Ok, I tried to call the SuspendEvent method finding there is only available one called SuspendEvents. I tried instead using this one and everything worked OK. I guess I may be running an older version of the library which does not include the SuspendEvent method. Anyway I solved the issue. Thank you very much.
You can close the case now.

Daniil
Nov 27, 2013, 4:04 AM
Yes, the SuspendEvent appeared not so far ago.