We wrote a generic "form is dirty" implementation on the body unload event. WebNumericEdit control has a blank space in the defaultValue property even when the control is not touched on the browser.
This check always return true in the javascript function.
if (type == "hidden" || type == "password" || type == "text" || type == "textarea" || type == "file") { if (element.value != element.defaultValue) { return true; } }
How do we differentiate this control with other elements? Is there a way to set the defaultValue to empty string?
Here is my HTML for the control -
<igtxt:WebNumericEdit ID="WebNumericEdit1" runat="server" HideEnterKey="true" SelectionOnFocus="CaretToEnd" DataMode="Decimal" Width="80px" Height="18px"></igtxt:WebNumericEdit>
Hi Ram,
Thanks for the update. Please update the forums if you need any further help with this issue.
Magued
Magued, you had this code in your HTML and I was not sure what it was doing -<ClientSideEvents Initialize="WebNumericEdit1_Initialize" />
But the sample Viktor provided help me to fix the problem. I could see what was done in the initialize event. I am still working to see if it breaks on some under condition.
Thanks to both of you for your guidance.
Was the reply from me and Victor helpful? Please update the forums if you would like to discuss this issue further?
Hi,
The WebTextEdit uses several hidden fields in order to support MSValidators and "back" feature of browser. The value of field which keeps track on view-state and validates "back" action has initial value equal to "\t". At the time of initialization on client, that value can be modified, so it will be not equal to defaultValue.
If your application uses (defaultValue!=value) as a flag for all fields in form including hidden, then I can suggest you to synchronize them for "view-state" field of controls which extend WebTextEdit by following.Note: WebTextEdit does not use defaultValue, so, it should not have side effects.
<script type="text/javascript">function edit_Initialize(oEdit, text){ //var vs = document.getElementById(oEdit.ID + '_p'); // or the same as above var vs = oEdit.elemViewState; if(vs) vs.defaultValue = vs.value;}</script><igtxt:WebNumericEdit ID="WebNumericEdit1" runat="server" HideEnterKey="true" SelectionOnFocus="CaretToEnd" DataMode="Decimal" Width="80px" Height="18px"> <ClientSideEvents Initialize="edit_Initialize" /></igtxt:WebNumericEdit><igtxt:WebTextEdit ID="anotherEditor" runat="server"> <ClientSideEvents Initialize="edit_Initialize" /></igtxt:WebTextEdit>
I have tried a code similar to the code that you posted and I am getting the element.value and the element.defaultValue equal. I have added a webNumericEdit control to a blank page. My code looks as follows:
function formisdirty() {
Number = document.getElementById("WebNumericEdit1"); if( Number.value != Number.defaultValue) { } }
<body onunload="formisdirty();"> <igtxt:WebNumericEdit ID="WebNumericEdit1" runat="server" DataMode ="Decimal" SelectionOnFocus="CaretToEnd" > <ClientSideEvents Initialize="WebNumericEdit1_Initialize" /></igtxt:WebNumericEdit>
Please send me more information on how to reproduce the issue.