This is a migrated thread and some comments may be shown as answers.

RadWindow not maintaining postback values correctly

1 Answer 109 Views
Window
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 18 May 2010, 12:04 AM
Hi, I am collecting information from the user in a RadWindow.

The RadWindow contains a repeater control.  Each item in the Repeater control contains a regular asp.net CheckBox and TextBox control.  When I iterate through the items of the repeater on postback, the items do not contain the values that were entered by the user, but default values instead.

The markup looks like this:

<telerik:RadWindowManager ID="RadWindowManager1" runat="server">

    <Windows>

         <telerik:RadWindow

                ID="rwManageCategories" 

                runat="server"

                Title="Manage Categories" 

                Height="400px"

                Width="600px" 

                Left="150px" 

                ReloadOnShow="true" 

                ShowContentDuringLoad="false" 

                Modal="true"

                Behaviors="None" 

                KeepInScreenBounds="True" 

                VisibleStatusbar="False"

         >

            <ContentTemplate>

                <asp:Label ID="lblRulesetCategories" runat="server"></asp:Label><br /><br />

                <asp:Label ID="lblErrorRulesetCategories" ForeColor="Red" runat="server"></asp:Label>

                <asp:Repeater ID="rptrRulesetCategories" runat="server">

                    <ItemTemplate>

                        <asp:CheckBox id="cbRulesetCategorySelected" Checked='<%# Eval("IsSelected") %>' runat="server"></asp:CheckBox>

                        <asp:HiddenField ID="hdnCategoryId" Value='<%# Eval("CategoryId") %>' runat="server" />

                        <asp:Label ID="lblRulesetCategoryName" Text='<%# Eval("Name") %>' runat="server"></asp:Label>

                        <asp:TextBox ID="tbRulesetCategorySequence" Text='<%# Eval("Sequence") %>' runat="server"></asp:TextBox>

                        <asp:CompareValidator ID="cvRulesetCategorySequence" ControlToValidate="tbRulesetCategorySequence" Operator="DataTypeCheck" Type="Integer" Text="* Invalid" Display="Dynamic" runat="server"></asp:CompareValidator>

                        <br />

                    </ItemTemplate>

                </asp:Repeater>

                <br />

                <br />

                <asp:Button ID="btnManageCategoriesSave" Text="Save" OnClick="btnManageCategoriesSave_Click" runat="server" />

                <asp:Button ID="btnManageCategoriesCancel" Text="Cancel" OnClick="btnManageCategoriesCancel_Click" runat="server" />

            </ContentTemplate>

         </telerik:RadWindow>

    </Windows>

</telerik:RadWindowManager>


The code-behind looks like this:

    protected void btnManageCategoriesSave_Click(object sender, EventArgs e)

    {

        // Get collection of checked ruleset categories in repeater

        var checkedCategoryIDs = from ri in this.rptrRulesetCategories.Items.Cast<RepeaterItem>()

                                 let hdnCategoryId = (HiddenField)ri.FindControl("hdnCategoryId")

                                 let cbRulesetCategorySelected = (CheckBox) ri.FindControl("cbRulesetCategorySelected")

                                 let tbRulesetCategorySequence = (TextBox)ri.FindControl("tbRulesetCategorySequence")

                                 select new

                                 {

                                     CategoryId = Convert.ToInt32(hdnCategoryId.Value),

                                     Checked = cbRulesetCategorySelected.Checked,

                                     Sequence = tbRulesetCategorySequence.Text == "" ? null : tbRulesetCategorySequence.Text

                                 };

}

When I hover over the checkedCategoryIDs variable, the Checked value is always false and the Sequence value is always blank for all items even though I do check various checkboxes, and enter values into various sequence textboxes.  This doesn't appear to be a problem with my LINQ statement, as I can also enter the following into the immediate window and still get a blank value:

? ((TextBox) this.rptrRulesetCategories.Items[0].FindControl("tbRulesetCategorySequence")).Text
""

The radwindow was working before when I was using a checkboxlist instead of a repeater, and I was using the same approach with collecting the values in a LINQ statement...

Any ideas on how I can resolve this?

Thanks,
James

** UPDATE **
My bad, the radwindow works fine.  I was rebinding the repeater, and erasing the values before I had a chance to retrieve them...

1 Answer, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 20 May 2010, 01:16 PM
Hi James,

I built up a tets demo based on your code and I was able to reproduce the problem. However, it turned out to be a general ASP problem because it can be reproduced without using RadWindow or any RadControls at all. I searched teh net and found the following solution:

http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.aspnet/2005-08/msg02915.html

I modified my demo accordingly and it started working. You can examine and test my sample code below:

markup:

<form id="form1" runat="server">
  <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
  </telerik:RadScriptManager>
  <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
      <Windows>
          <telerik:RadWindow ID="rwManageCategories" runat="server" Title="Manage Categories"
              Height="400px" Width="600px" Left="150px" ReloadOnShow="true" VisibleOnPageLoad="true"
              ShowContentDuringLoad="false" Modal="true" Behaviors="None" KeepInScreenBounds="True"
              VisibleStatusbar="False">
              <ContentTemplate>
                  <asp:Label ID="lblRulesetCategories" runat="server"></asp:Label><br />
                  <br />
                  <asp:Label ID="lblErrorRulesetCategories" ForeColor="Red" runat="server"></asp:Label>
                  <asp:Repeater ID="rptrRulesetCategories" runat="server" EnableViewState="false">
                      <ItemTemplate>
                          <asp:TextBox ID="tbRulesetCategorySequence" Text='<%# Eval("FirstColumn") %>' runat="server"></asp:TextBox>
                          <br />
                      </ItemTemplate>
                  </asp:Repeater>
                  <br />
                  <br />
                  <asp:Button ID="btnManageCategoriesSave" Text="Save" OnClick="btnManageCategoriesSave_Click"
                      runat="server" />
                  <asp:Button ID="btnManageCategoriesCancel" Text="Cancel" runat="server" />
              </ContentTemplate>
          </telerik:RadWindow>
      </Windows>
  </telerik:RadWindowManager>
  </form>

code - behind:

protected void Page_Load(object sender, EventArgs e)
{
    rptrRulesetCategories.DataSource = GetData();
    rptrRulesetCategories.DataBind();
}
protected void btnManageCategoriesSave_Click(object sender, EventArgs e)
{
    Response.Write(((TextBox)rptrRulesetCategories.Controls[0].Controls[1]).Text);
}
protected DataTable GetData()
{
    DataTable tbl = new DataTable();
    tbl.Columns.Add(new DataColumn("FirstColumn"));
    tbl.Columns.Add(new DataColumn("SecondColumn"));
    tbl.Columns.Add(new DataColumn("ThirdColumn"));
    tbl.Columns.Add(new DataColumn("FourthColumn"));
    tbl.Rows.Add(new object[] { "firstRecord1", "firstRecord2", "firstRecord3", "firstRecord4" });
    tbl.Rows.Add(new object[] { "secondRecord1", "secondRecord2", "secondRecord3", "secondRecord4" });
    tbl.Rows.Add(new object[] { "thirdRecord1", "thirdRecord2", "thirdRecord3", "thirdRecord4" });
    return tbl;
}

I hope that my reply and research are helpful.


Regards,
Svetlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Window
Asked by
James
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Share this question
or