Custom Property that can be set client side and posted back to the server

  1. #1

    Custom Property that can be set client side and posted back to the server

    I am trying to add a "ClientIsDirty" property to a control I am extending from TextField. I want to be able to set this on the client, and it should be available in the direct event. I want this to be as seemless as using the "Text" property on the server side (don't want to deal with extraparams, etc).

    Thanks for your help.
  2. #2
    Hi,

    Please see #3
    http://forums.ext.net/showthread.php...ll=1#post31657

    Regarding to:
    it should be available in the direct event.
    It needs to override the LoadPostData method.

    As an example you can consider .LoadPostData() of the Ext.Net.TextFieldBase class.
    Last edited by Daniil; Aug 11, 2011 at 8:18 AM.
  3. #3
    Thank you for your reply. Can you provide a short example of what I should put in the overridden LoadPostData?
    Thanks.
  4. #4
    Please just look at the .LoadPostData() method of the Ext.Net.TextFieldBase.
    Last edited by Daniil; Aug 11, 2011 at 2:32 PM.
  5. #5
    Excuse my ignorance, but what is "epy"?
    Also, I looked at LoadPostData, but it seems that the postCollection contains one key/value pair per field. The key is the UniqueName of the field, and the value is the Value property. I don't see how this can be extended to contain extra properties.

    Thanks

    protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)        
    {
                this.HasLoadPostData = true;
    
    
                string val = postCollection[this.UniqueName];
                val = val != null && val.Equals(this.EmptyText) ? "" : val;
    
    
                this.SuspendScripting();
                this.RawValue = val;
                this.ResumeScripting();
    
    
                if (val != null && this.Text != val)
                {
                    bool raise = val != (this.Text ?? "");
    
    
                    try
                    {
                        this.SuspendScripting();
                        this.Text = val.Equals(this.EmptyText) ? "" : val;
                    }
                    finally
                    {
                        this.ResumeScripting();
                    }
    
    
                    return raise;
                }
    
    
                return false;
    }
  6. #6
    You have to create hidden field and place a value to that hidden field
    After that the value will be available in the postCollection
  7. #7
    Thanks!! It worked. Below is the extended class.
    I appreciate your help.

    Public Class TxtField
            Inherits Ext.Net.TextField
    
            Public Property IsDirty As Boolean
    
            Public Sub New()
                AddHandler Me.Init, AddressOf TxtField_Init
            End Sub
    
            Protected Sub TxtField_Init(sender As Object, e As System.EventArgs)
                Dim txt = CType(sender, TxtField)
    
                txt.Controls.Add(New HiddenField With {.ID = ID & "IsDirty", .ClientIDMode = UI.ClientIDMode.Static})
                txt.Listeners.Change.Handler = String.Format("$('#{0}').val(this.originalValue != this.getValue());", ID & "IsDirty")
            End Sub
    
            Protected Overrides Function LoadPostData(postDataKey As String, postCollection As System.Collections.Specialized.NameValueCollection) As Boolean
                Boolean.TryParse(postCollection(UniqueID & "IsDirty"), IsDirty)
                Return MyBase.LoadPostData(postDataKey, postCollection)
            End Function
        End Class

Similar Threads

  1. Replies: 3
    Last Post: Dec 26, 2011, 1:32 PM
  2. Replies: 1
    Last Post: Dec 01, 2010, 5:14 PM
  3. Close window - client and server side
    By Hanza in forum 1.x Help
    Replies: 1
    Last Post: Aug 23, 2010, 2:00 PM
  4. Replies: 4
    Last Post: Mar 19, 2010, 11:35 AM
  5. Replies: 6
    Last Post: Sep 01, 2009, 1:06 PM

Tags for this Thread

Posting Permissions