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

WebUserControl Edit Form in a Grid Edit Modal Pop-Up...

3 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josue
Top achievements
Rank 1
Josue asked on 22 Feb 2011, 05:07 AM
Hi,

First of all this topic is referenced with this topic http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-edit-command-doesnt-work.aspx in a sense of the logic of the application.

So my question is...
I read the documentation and tested the demos, everything is working as expected but when i want to close or cancel the modal pop-up (lets say i don't wanna edit, update or insert anything) the modal pop-up get stuck and cant get to close/hide it.
I intended to handle de oncancel event in the radgrid but nothing, tested if it was a browser issue and in ie8, ff3.6 and chrome-latest still get the same result.
But here is the rare thing m binding with the publiC DataItem object and if i delete this bindings (currently getting "binded" in the page_load event of the usercontrol) everything just work as always, if a make a bind even just one it get stuck, do i forget to handle and a event?...

Users.aspx
<%@ Page Title="Users | Telerik Trial Testing" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Users.aspx.cs" Inherits="TelerikTrial.Users" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadComboBox ID="App_List" runat="server" AutoPostBack="true" DataTextField="ApplicationName"
        DataValueField="LoweredApplicationName" OnSelectedIndexChanged="App_List_SelectedIndexChanged">
    </telerik:RadComboBox>
    <br />
    <telerik:RadAjaxManager runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="App_List">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="App_List" />
                    <telerik:AjaxUpdatedControl ControlID="User_List" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="User_List">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="App_List" />
                    <telerik:AjaxUpdatedControl ControlID="User_List" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <telerik:RadGrid ID="User_List" runat="server" AllowPaging="True"
        AutoGenerateColumns="False" GridLines="None"
        Skin="Windows7" OnPageIndexChanged="User_List_PageIndexChanged">
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
        <MasterTableView EditMode="PopUp" CommandItemDisplay="Top" DataKeyNames="UserName">
            <EditFormSettings UserControlName="CustomEditControlForm.ascx" EditFormType="WebUserControl" InsertCaption="Add new user" CaptionFormatString="Edit User: {0}"
                CaptionDataField="UserName" PopUpSettings-Modal="true" />
            <Columns>
                <telerik:GridEditCommandColumn />
                <telerik:GridClientDeleteColumn />
                <telerik:GridBoundColumn DataField="UserName" ReadOnly="true" />
                <telerik:GridBoundColumn DataField="Email" />
                <telerik:GridBoundColumn DataField="LastLoginDate" ReadOnly="true" />
                <telerik:GridCheckBoxColumn DataField="IsLockedOut" />
            </Columns>
        </MasterTableView>
         <ClientSettings>
            <ClientEvents OnRowDblClick="RowDblClick" />
        </ClientSettings>
    </telerik:RadGrid>
</asp:Content>


CustomEditControlForm.ascx
<%@ Control Language="c#" Inherits="TelerikTrial.CustomEditControlForm"
    CodeFile="CustomEditControlForm.ascx.cs" %>
 
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>

CustomEditControlForm.ascx.cs
using System;
using System.Data;
using System.Collections;
using System.Web.UI;
using Telerik.Web.UI;
 
namespace TelerikTrial.CustomEditControlForm
{
    public partial class CustomEditControlForm : System.Web.UI.UserControl
    {
        private object _dataItem = null;
 
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
         
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // With just this binding the modal get stucks and the browser can't hide it...
            TextBox1.Text = DataBinder.Eval( This.Parent.NamingContainer, "DataItem.UserName").ToString();
        }
    }
}

Best Regards

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Feb 2011, 06:57 AM
Hello Jouse,

You can simply populate the TextBox from ascx like below and check whether it solves the issue.

ASCX:
<asp:TextBox ID="TextBox1" Text='<%#Eval("UserName") %>' runat="server">
</asp:TextBox>

Thanks,
Princy.
0
Josue
Top achievements
Rank 1
answered on 22 Feb 2011, 05:25 PM
Thanks Princy,

That did it but a side question...
How can i programatically (from code-behind) can bind or grab dataitem values without breaking my modal pop-up behavior?
did you know how to do it?

Regards
0
Princy
Top achievements
Rank 2
answered on 23 Feb 2011, 06:22 AM
Hello Josue,

If you want to do the same from code behind try the following code snippet in ItemDataBound event of RadGrid.

C#:
protected void User_List_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
        {
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
            UserControl userControl = (UserControl)editItem.FindControl(GridEditFormItem.EditFormUserControlID);
            TextBox txtbox = (TextBox)userControl.FindControl("TextBox1");
            txtbox.Text = (string)DataBinder.Eval(e.Item.DataItem, "UserName").ToString();
        }
    }

Thanks,
Princy.
Tags
Grid
Asked by
Josue
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Josue
Top achievements
Rank 1
Share this question
or