Showing posts with label formview. Show all posts
Showing posts with label formview. Show all posts

Wednesday, March 21, 2012

Trying to make the CascadingDropDown read only

Hi, i'm trying to stop the CascadingDropDown value from being changed when the item the user is editing (via the formview control) is blocked. I notice there is no read only property on the DropDownList control or on the CascadingDropDown control so I figured the best way to do this was to disable the control and add a hidden field which would post the original value back.

<asp:Label ID="lblSectionIDValue" runat="server" Text='<%# Eval("SectionName") %>' Visible='<%# (bool)Eval("Blocked") %>'></asp:Label>
<asp:HiddenField ID="hfdSectionID" runat="server" Value='<%# Bind("SectionID") %>' Visible='<%# (bool)Eval("Blocked") %>' />
<asp:DropDownList ID="lstSectionID" runat="server" Visible='<%# !(bool)Eval("Blocked") %>'>
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="cddSectionID" runat="server" TargetControlID="lstSectionID" Category="Section" PromptText="-- Please Select --" LoadingText="[Loading sections...]" ServicePath="~/CascadingDropdownsService.asmx" ServiceMethod="GetSectionsList" SelectedValue='<%# Bind("SectionID") %>' Enabled='<%# !(bool)Eval("Blocked") %>' />

However a null value is being posted back instead of the original value. I've tried just about every combination now but nothing works. Without the CascadingDropDown control i can successfully say:

<asp:HiddenField ID="hfdSectionID" runat="server" Value='<%# Bind("SectionID") %>' Visible='<%# (bool)Eval("Blocked") %>' />
<asp:DropDownList ID="lstSectionID" runat="server" SelectedValue='<%# Bind("SectionID") %>' Enabled='<%# !(bool)Eval("Blocked") %>'>
</asp:DropDownList>

which posts the value back.

I think there is a bug in that some value is being sent back if the CascadingDropDown's enabled property is set to false and is overriding the value in the hidden field.

Hi here's a fix which creates a new property called EnabledOverride and works like the Enabled property for the standard controls such as the TextBox.

Edit CascadingDropDownExtender.cs:
============================

Add
-----
private const string stringEnabledOverride = "EnabledOverride";
-----

Add
-----
[DefaultValue("")]
[ExtenderControlProperty()]
public bool EnabledOverride
{
get
{
return GetPropertyValue(stringEnabledOverride, true);
}
set
{
SetPropertyValue(stringEnabledOverride, value);
}
}
-----

Edit CascadingDropDownBehaviour.js:
============================

Add
-----
this._enabledOverride = null;
-----

Add
-----
get_EnabledOverride : function() {
/// <value type="String">
/// Whether the drop down is enabled
/// </value>
return this._enabledOverride;
},
set_EnabledOverride : function(value) {
if (this._enabledOverride != value) {
this._enabledOverride = value;
this.raisePropertyChanged('EnabledOverride');
}
},
-----

Add (at the bottom of _setOptions function)
-----
_setOptions function (at the bottom):

// Disable the control if not enabled
if (!this._enabledOverride) {
e.disabled = true;
}
-----

Hope this helps you as much as it has me :).


You can try enclosing dropdown and cascadingdropdown in a server Div:





           <div runat="server" id="divEstado">



                                <asp:DropDownList ID="ddlEstado" runat="server" ></asp:DropDownList>



                                <cc1:CascadingDropDown ID="cddEstado" runat="server" TargetControlID="ddlEstado"



                                Category="Estado" PromptText="[Select value...]" ServicePath="Services.asmx"



                                ServiceMethod="FillData" UseContextKey="true" ParentControlID="ddlPais" /> 



          </div>



Disabling in code behind:



divEstado.Disabled = true;



Disabling in javascript:



$get('<%=divtrEstado.ClientID%>').disabled = 'disabled';


You can try enclosing dropdown and cascadingdropdown in a server Div:





           <div runat="server" id="divEstado">



                                <asp:DropDownList ID="ddlEstado" runat="server" ></asp:DropDownList>



                                <cc1:CascadingDropDown ID="cddEstado" runat="server" TargetControlID="ddlEstado"



                                Category="Estado" PromptText="[Select value...]" ServicePath="Services.asmx"



                                ServiceMethod="FillData" UseContextKey="true" ParentControlID="ddlPais" /> 



          </div>



Disabling in code behind:



divEstado.Disabled = true;



Disabling in javascript:



$get('<%=divtrEstado.ClientID%>').disabled = 'disabled';

Two-way data binding problem with Atlas UpdatePanel

I have an existing ASP 2.0 page which utilizes a SQLDataSouce and a FormView with bound controls. The page has a "save" button which saves the contents of the bound controls to the database. It works fine when not using Atlas.

One of the textboxes on the form is a date field. I want to use Atlas and the .Net Calendar control to provide a popup calendar. I implemented the calander based upon some simple example code I found in the Atlas tutorial. The popup works great and the value from the calendar is correctly placed into the target textbox.

The problem I am having is that wrapping the UpdatePanel around the textbox causes it to lose two-way databinding.It correctly displays the initial value from the current database record but, when attempting to do and update the value is always NULL. Does anyone know what I may be missing. Below is the Atlas markup wrapped around the textbox:

Thanks,

Tony

<atlas:updatepanel id="upCallReportDateTime" runat="server" mode="Conditional" rendermode="Inline"
<triggers>
<atlas:controleventtrigger controlid="calDatePicker" eventname="SelectionChanged" />
</triggers>

<contenttemplate>
<asp:textbox id="txtCallReportDateTime" runat="server"
Width="150px"
Text='<%# Bind("CallReportDateTime") %>'
CssClass="EditTextBox"
ontextchanged="txtCallReportDateTime_TextChanged"
autopostback="true"/>
<asp:imagebutton id="cmdPickDate_CallReportDateTime" runat="server"
onclick="cmdPickDate_CallReportDateTime_Click"
imageurl="graphics/calendar.gif"
height="20px"
width="20px"
CausesValidation="false" />
</contenttemplate>
</atlas:updatepanel>

Were you ever able to solve this problem? I am having the exact same problem.

The only way I've solved it so far is to add the missing parameter in the FormView_ItemInserting event.

This works well but it seems like I shouldn't have to do that.