Nov 07, 2011, 10:57 PM
Disabled checkbox loses value on postback
Ext.Net 1.2
.Net 4.0
To reproduce using the code below, press button 1.) then 2.)
The problem might be in the LoadPostData method of CheckBox.cs
Possible Fix:
In Form\Checkbox.cs
.Net 4.0
To reproduce using the code below, press button 1.) then 2.)
The problem might be in the LoadPostData method of CheckBox.cs
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="cbox.aspx.vb" Inherits="cbox" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<div style="margin-left: 10px;">
<ext:Button runat="server" ID="btn1" Text="1.) Check & Set Disabled" AutoPostBack="true" OnClick="setProperties">
</ext:Button>
<ext:Button runat="server" ID="btn2" Text="2.) Do Post" AutoPostBack="true" OnClick="doPost">
</ext:Button>
<ext:Checkbox runat="server" ID="chk1">
</ext:Checkbox>
</div>
</form>
</body>
</html>
Partial Class cbox
Inherits System.Web.UI.Page
Protected Sub doPost(sender As Object, e As System.EventArgs)
Response.Write("chk1.Checked = " & chk1.Checked)
End Sub
Protected Sub setProperties(sender As Object, e As System.EventArgs)
chk1.Disabled = True
chk1.Checked = True
End Sub
End Class
Possible Fix:
In Form\Checkbox.cs
protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
this.HasLoadPostData = true;
string val = postCollection[this.UniqueName];
this.SuspendScripting();
this.RawValue = val;
try
{
bool result = this.Checked != val.IsNotEmpty();
if (this.Checked && this.Disabled)
{
this.Checked = true;
}
else {
this.Checked = val.IsNotEmpty();
}
return result;
}
catch
{
}
finally
{
this.ResumeScripting();
}
return true;
}
Last edited by zach; Nov 07, 2011 at 11:39 PM.
Reason: Added possible fix