TextField text disappearing

  1. #1

    TextField text disappearing

    I have the following markup defining a form.

    <ext:LayoutColumn>
    <ext:Panel ID="pnlRoleDetails" runat="server" Frame="false" Title="Role Details" Height="474" Width="300" AutoScroll="true" BodyStyle="padding:5px;background-color:#e8e8e8;">
    <Body>
    <ext:FieldSet ID="FieldSet3" runat="server" CheckboxToggle="false" Title="Role" AutoHeight="true" >
    <Body> 
    <ext:FormLayout ID="FormLayout1" runat="server" LabelWidth="75" LabelSeparator="" LabelAlign="Top">
    <ext:Anchor>
    <ext:TextField ID="txtRoleName" runat="server" FieldLabel="" AllowBlank="false" Width="260" ReadOnly="true" />
    </ext:Anchor>
    </ext:FormLayout>
    </Body>
    </ext:FieldSet>
    <ext:FieldSet ID="Fieldset50" runat="server" CheckboxToggle="true" Title="Description" Collapsed="true">
    <Body>
    <ext:FormLayout ID="FormLayout11" runat="server" LabelWidth="75" LabelAlign="Top" LabelSeparator="">
    <ext:Anchor>
    <ext:TextArea ID="txtDescription" runat="server" FieldLabel="" AllowBlank="false" Text="" Width="260" />
    </ext:Anchor> 
    </ext:FormLayout> 
    </Body>
    </ext:FieldSet>
    <ext:FieldSet ID="FieldSet4" runat="server" CheckboxToggle="true" Title="Privileges" AutoHeight="true" Collapsed="true">
    <Body> 
    <ext:FormLayout ID="frmPrivileges" runat="server" LabelWidth="75">
    <ext:Anchor>
    <ext:Checkbox ID="chkSearch" runat="server" FieldLabel="Search" StateID="1"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkAdd" runat="server" FieldLabel="Add" StateID="2"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkDelete" runat="server" FieldLabel="Delete" StateID="3"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkEdit" runat="server" FieldLabel="Edit" StateID="4">
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkQuery" runat="server" FieldLabel="Query" StateID="5"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkAmend" runat="server" FieldLabel="Amend" StateID="6"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkApprove" runat="server" FieldLabel="Approve" StateID="7"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkCancel" runat="server" FieldLabel="Cancel" StateID="8"> 
    </ext:Checkbox>
    </ext:Anchor> 
    <ext:Anchor>
    <ext:Checkbox ID="chkComplete" runat="server" FieldLabel="Complete" StateID="9"> 
    </ext:Checkbox>
    </ext:Anchor> 
    </ext:FormLayout> 
    </Body>
    </ext:FieldSet> 
    <ext:FieldSet ID="FieldSet5" runat="server" CheckboxToggle="true" Title="Users in Role" Collapsed="true" AutoHeight="true" >
    <Body> 
    <ext:FormLayout ID="FormLayout3" runat="server" LabelWidth="75" LabelAlign="Top" LabelSeparator="">
    <ext:Anchor>
    <ext:MultiSelect ID="listUsers" runat="server" FieldLabel="" AutoPostBack="false" Width="260">
    </ext:MultiSelect>
    </ext:Anchor>
    </ext:FormLayout>
    </Body>
    </ext:FieldSet> 
    </Body>
    <TopBar>
    <ext:Toolbar ID="Toolbar2" runat="server">
    <Items>
    <ext:ToolbarButton ID="btnAddRole" runat="server" Text="Add" Icon="UserOrange" AutoPostBack="false">
    <AjaxEvents>
    <Click OnEvent="btnAddRole_Click" />
    </AjaxEvents>
    </ext:ToolbarButton>
    <ext:ToolbarButton ID="btnSaveRole" runat="server" Text="Save" Icon="Accept" AutoPostBack="false">
    <AjaxEvents>
    <Click OnEvent="btnSaveRole_Click" />
    </AjaxEvents>
    </ext:ToolbarButton>
    <ext:ToolbarButton ID="btnRemoveUsers" runat="server" Text="Remove Users" Icon="UserDelete" AutoPostBack="false">
    </ext:ToolbarButton> 
    </Items>
    </ext:Toolbar>
    </TopBar>
    </ext:Panel>
    </ext:LayoutColumn>
    and the following code behind to handle a click event

    protected void btnSaveRole_Click(object sender, AjaxEventArgs e)
    {
    // save role in authentication database
    if (!Roles.RoleExists(txtRoleName.Text))
    {
    Roles.CreateRole(txtRoleName.Text);
    // save role in ea database
    Role.CreateUserRole(txtRoleName.Text);
    // save privileges for role in ea databse
    List<int> privs = new List<int>();
    foreach (Checkbox cb in frmPrivileges.Controls)
    {if (cb.Checked)
    privs.Add(Convert.ToInt32(cb.StateID));
    }
    Privileges.CreatePrivileges(txtRoleName.Text, privs.ToArray());
    }
    }
    If I enter text in the 'txtRoleName' textfield it is empty when I come to get the value in the code-behind. I have done a search on txtRoleName.Text in my code-behind to make sure I do not empty the field the only time I do this is when I call an 'Add' function which clears the fields and makes ReadOnly = false.

    Can anyone shed any light on this for me please?
  2. #2

    RE: TextField text disappearing

    *Hi,

    Can you show full example which reproduces the problem? There was same requests but we have no code which reproduces this problem. If you can create simple example which reproduces the problem we will investigate it ASAP. Also can be that problem exists in 0.7 version but fixed in current version


  3. #3

    RE: TextField text disappearing

    Just to add more info, if I set the text to some value (e.g. TestValue) at design time in markup. Then I use my Add function to clear the fields ready for new data

    protected void btnAddRole_Click(object sender, AjaxEventArgs e)
    {
    ClearRoleFields();
    hidNewRole.Text = "true";
    txtRoleName.ReadOnly = false;
    txtRoleName.Enabled = true;
    txtRoleName.Focus();
    }
    
    
    
    private void ClearRoleFields()
    {
    txtRoleName.Text = "";
    txtDescription.Text = "";
    foreach (Anchor an in frmPrivileges.Anchors)
    {
    foreach (Checkbox chk in an.Items)
    {
    chk.Checked = false;
    }
    }
    Then when I use the save option as mentioned before this time the original text of TestValue returns. Therefore what is happening is that the design time text values is not being changed.
  4. #4

    RE: TextField text disappearing

    OK I will extract this chunk into a small app but I have created the behaviour I want earlier in another part of this application and it works OK.
  5. #5

    RE: TextField text disappearing

    I have attached a zipped solution in which this occurs. I think it is to do with the tabs and the DeferredRender etc.

    I forget the reason why I used this but I had a problem in a previous project for which you advised using DeferredRender and it fixed it. So I used it again.

    If you stop in the code-behind click events you will see that the original text value of the TextField is mantained.
  6. #6

    RE: TextField text disappearing

    Hi,

    I reproduce the problem with 0.7 version. But in 0.8 it is fixed already. Until new release you can use the following workaround


    1. Set*ViewStateMode="Include" for*btnAddUser Click ajax event
    2. Set*ViewStateMode="Include" for*btnAddRole*Click ajax event*


  7. #7

    RE: TextField text disappearing

    This has fixed the empty text.


    Because the screen is also used for editing I have applied the same property to the RowSelect event of a grid list of roles where the same problem was occurring.

    However on the add I now have a different problem. I get this error.

    Error Details: Failed to load viewstate. The control tree into which viewstate is being loaded
    must match the control tree that was used to save viewstate during the previous request. 
    For example, when adding controls dynamically, the controls added during a post-back must 
    match the type and position of the controls added during the initial request.

    protected void btnSaveRole_Click(object sender, AjaxEventArgs e)
    {
    // save role in authentication database
    if (!Roles.RoleExists(txtRoleName.Text))
    {
    Roles.CreateRole(txtRoleName.Text);
    // save role in ea database
    Role.CreateUserRole(txtRoleName.Text);
    // save privileges for role in ea databse
    List<int> privs = new List<int>();
    foreach (Checkbox cb in frmPrivileges.Controls)
    {
    if (cb.Checked)
    privs.Add(Convert.ToInt32(cb.StateID));
    }
    Privileges.CreatePrivileges(txtRoleName.Text, privs.ToArray());
    PopulateRolesGrid();
    }
    } 
    
    
    private void PopulateRolesGrid()
    {
    List<object> userData = new List<object>();
    foreach (string roleName in this.AllRoles)
    {
    object[] row = new object[] { roleName, "description" };
    userData.Add(row);
    }
    rolesStore.DataSource = userData;
    rolesStore.DataBind();
    }
    The new role becomes available as a new checkbox on the Users tab. These checkboxes are added dynamically on first load. Is this waht is causing the error?
  8. #8

    RE: TextField text disappearing

    I am no longer getting the error by attempting to add the new role checkbox however the checkbox is not visible.


    I load checkboxes dynamically on Page_Init

    
    
    
    protected void Page_Init(object sender, EventArgs e)
    {
    this.AllRoles = Roles.GetAllRoles();
    foreach (string roleName in AllRoles)
    {
    if (roleName != ConfigurationManager.AppSettings["AdministratorRoleName"])
    {
    // add role checkboxes to user 
    Anchor an = new Anchor();
    Checkbox chk = new Checkbox();
    chk.ID = "chk" + roleName;
    chk.FieldLabel = roleName;
    chk.Checked = false;
    an.Items.Add(chk);
    frmRoles.Anchors.Add(an);
    }
    }
    }
    
    
    
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Ext.IsAjaxRequest)
    {
    // Load Contracts
    this.Contracts = Contract.GetAllContracts();
    // Load Regions
    this.Regions = Region.GetAllRegions();
    // users Grid
    PopulateUsersGrid();
    // Role grid
    PopulateRolesGrid();
    contractStore.DataSource = this.Contracts;
    contractStore.DataBind();
    cboContract.SelectedItem.Value = "0";
    regionStore.DataSource = this.Regions;
    regionStore.DataBind();
    cboRegion.SelectedItem.Value = "0";
    }
    }
    In another section of my code I attempt to add the new checkbox to these but I cannot get it to display. Can you please tell me how I do this. Is it something I cannot do in code-behind?

    
    
    
    
    protected void btnSaveRole_Click(object sender, AjaxEventArgs e)
    {
    // save role in authentication database
    if (!Roles.RoleExists(txtRoleName.Text))
    {
    Roles.CreateRole(txtRoleName.Text);
    // save role in ea database
    Role.CreateUserRole(txtRoleName.Text);
    // save privileges for role in ea databse
    List<int> privs = new List<int>();
    foreach (Checkbox cb in frmPrivileges.Controls)
    {
    if (cb.Checked)
    privs.Add(Convert.ToInt32(cb.StateID));
    }
    Privileges.CreatePrivileges(txtRoleName.Text, privs.ToArray());
    // add new role checkbox to user 
    Anchor an = new Anchor();
    Checkbox chk = new Checkbox();
    chk.ID = "chk" + txtRoleName.Text;
    chk.FieldLabel = txtRoleName.Text;
    chk.Checked = false;
    an.Items.Add(chk);
    frmRoles.Anchors.Add(an);
    this.AllRoles = Roles.GetAllRoles();
    PopulateRolesGrid();
    }
    }
  9. #9

    RE: TextField text disappearing

    Anyone have any ideas on my dynamic checkboxes - thanks.

Similar Threads

  1. TextField.Text when save alway plus ','
    By vcongit in forum 2.x Help
    Replies: 5
    Last Post: Nov 06, 2012, 5:53 PM
  2. [CLOSED] Get Dynamic TextField Text...
    By gs_user in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Apr 24, 2012, 3:56 AM
  3. ext:TextField text wrap please help
    By gopikrishna in forum 1.x Help
    Replies: 0
    Last Post: Feb 14, 2011, 7:50 AM
  4. [CLOSED] Cannot set the text in a TextField
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 12, 2010, 4:34 PM
  5. TextField.Text is allways empty
    By Puia in forum 1.x Help
    Replies: 3
    Last Post: Apr 02, 2009, 12:28 PM

Posting Permissions