PDA

View Full Version : [FIXED] [V0.8.0] Can't get/set value for TextField Readonly



Simon King
Feb 01, 2009, 8:12 AM
Dear team,

I found a strange behavior in code AjaxEvent for ext:textfield control.

Refer to below code, "TextField" should be a readonly control, but the value can be change in ajaxevent when click "Button2". When click "Button1", the value of "TextField" will be copy to a normal control "Result", so to verify the control value.

In below code, the set/get function is ok, when I click the button 1 and 2, the value can be update.

But if I change the readonly property in aspx like below:


<ext:TextField ID="TextField" runat="server" Text="test" ReadOnly="true" >

or in Page_Load event:


protected void Page_Load(object sender, EventArgs e)
{
TextField.ReadOnly = true;
}

the function is not ok, the text property of "TextField" is alwasy "test"(the init value).


test.aspx:



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Web.test" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>

<form id="form1" runat="server">

<br />TextField:
<ext:TextField ID="TextField" runat="server" Text="test" ReadOnly="false" >
</ext:TextField>
<ext:Button ID="Button1" runat="server" Text="testTextField">
<AjaxEvents >
<Click OnEvent="testTextField"></Click>
</AjaxEvents>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="setvalue">
<AjaxEvents >
<Click OnEvent="setTextField"></Click>
</AjaxEvents>
</ext:Button>

<br />Result
<ext:TextField ID="Result" runat="server">
</ext:TextField>
<br />



</form>
</body>
</html>



test.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coolite.Ext;
using Coolite.Ext.Web;
namespace Web
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//TextField.ReadOnly = true;
}


protected void testTextField(object sender, AjaxEventArgs e)
{
Result.Text = TextField.Text;
}


protected void setTextField(object sender, AjaxEventArgs e)
{
TextField.ReadOnly = true;
TextField.Text = System.DateTime.Now.ToString() ;
}
}
}


I also test other ext control, same problem in textarea control, but no problem in ext:DateField and ext:Checkbox control when readonly set to true.
Just for your reference, pls help find the rootcause, thanks.

Vladimir
Feb 01, 2009, 9:23 AM
Hi,

Try to set ViewStateMode="Include" for AjaxEvent.


<ext:Button ID="Button2" runat="server" Text="setvalue">
    <AjaxEvents >
        <Click ViewStateMode="Include" OnEvent="setTextField"></Click>
    </AjaxEvents>
</ext:Button>


Plus in 0.7 version the TextField and TextArea excluding from submit if they are ReadOnly (it can be a problem if you change it programatically on client side). In 0.8.0 it is changed (readonly text field submit your value)

Simon King
Feb 01, 2009, 11:40 PM
It works, thanks Vladimir, so kind of you.
Pls mark this thread as resolved.