Hello everyone and special thanks to Princy!
I am using a Radgrid with a Radwindow on Editing , you can see all about it in “Demo/Asp.Net Ajax/Window/Edit Dialog For RadGrid”
I tried it to customize it in my Project logic and every thing is fine when I use the same structure(DefaultCS.aspx, and code behind and EditForm and its codebehind).
But I am using a UserControl instead of aspx file ,as follow :
Root
.
.
.
Folder :Usercontrols
ChargePanel.ascx(Instead of DefaultCS.aspx)[Inherited from SiteMasterpage]
EditForm.aspx
SiteMasterPage.master
When I click On Edit Button everything is true still, and works fine ,and the Grid will be updated after closing windows with some Java Script Code,after do that if I tend to edit another row when I click the Edit button It will raise an error!
Microsoft JScript runtime error: 'null' is null or not an object
Here is my Code,I have tried to find a solution from Many posts but I didn’t find anything to help me…
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChargePanelCS.ascx.cs" Inherits="UserControls_ChargePanel" %><telerik:RadCodeBlock ID="RadCodeBlock2" runat="server"> <style type="text/css"> .orderText { font: normal 12px Arial,Verdana; margin-top: 6px; } .expandImage { display: inline-block; background-image: url('<%= Page.ResolveUrl("~/Common/styles09/sprite09.gif")%>'); background-position: -596px -1191px; background-repeat: no-repeat; width: 15px; height: 15px; } * html .expandImage { background-position: -596px -1194px; } * + html .expandImage { background-position: -596px -1194px; } </style></telerik:RadCodeBlock><telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> function ShowEditForm(id, rowIndex) { var grid = $find("<%= RadGrid1.ClientID %>"); var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element(); grid.get_masterTableView().selectItem(rowControl, true); window.radopen("../UserControls/EditFormCS.aspx?PanelId=" + id, "UserListDialog"); return false; } function ShowInsertForm() { window.radopen("../UserControls/EditFormCS.aspx", "UserListDialog"); return false; } function refreshGrid(arg) { if (!arg) { $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind"); } else { $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate"); } } function RowDblClick(sender, eventArgs) { window.radopen("../UserControls/EditFormCS.aspx?PanelId=" + eventArgs.getDataKeyValue("PanelId"), "UserListDialog"); } </script></telerik:RadCodeBlock> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadGrid ID="RadGrid1" runat="server" CssClass="myRadGrid" AllowPaging="true" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" PageSize="10" Font-Names="Tahoma" dir="rtl" AllowFilteringByColumn="true" OnUpdateCommand="RadGrid1_UpdateCommand" OnItemCreated="RadGrid1_ItemCreated"> <ExportSettings IgnorePaging="true" OpenInNewWindow="true"> <Pdf PageHeight="297mm" PageWidth="210mm" PageTitle="SushiBar menu" /> </ExportSettings> <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" TableLayout="Auto" Font-Names="Tahoma" DataKeyNames="PanelId" EditMode="PopUp"> <%--<EditFormSettings InsertCaption="ركورد جديد" CaptionFormatString="ويرايش" CaptionDataField="PanelId" PopUpSettings-Modal="true" FormCaptionStyle-Font-Names="Tahoma" EditColumn-HeaderStyle-Font-Names="Tahoma" />--%> <CommandItemTemplate> <div style="padding: 5px 5px;" dir="rtl"> <asp:LinkButton ID="LinkButton4" runat="server" Font-Names="Tahoma" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../Images/Icons/Refresh.gif" />به روزآوري اطلاعات</asp:LinkButton> </div> </CommandItemTemplate> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> <ItemStyle CssClass="MyImageButton" /> </telerik:GridEditCommandColumn> <telerik:GridBoundColumn AllowSorting="true" DataField="PanelName" HeaderText="نام پنل" SortExpression="PanelName" UniqueName="PanelName" ColumnEditorID="GridTextBoxColumn"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="رده بندي ارسال"> <ItemTemplate> <telerik:RadRating dir="rtl" ID="RadRating1" runat="server" AutoPostBack="true" Value='<%# Convert.ToDouble(Eval("Used_Charges_Send"))/100000 %>' OnRate="RadRating1_Rate" ReadOnly="true" Precision="Item" ItemCount="10" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn AllowSorting="true" DataField="N_Charges_Send" HeaderText="شارژ ارسال" SortExpression="N_Charges_Send" UniqueName="N_Charges_Send" ItemStyle-CssClass="grid_txt_NO" ColumnEditorID="GridTextBoxColumn"> </telerik:GridBoundColumn> <telerik:GridBoundColumn AllowSorting="true" DataField="Fake_Charges_Send" HeaderText="شارژ اضطراري" SortExpression="Fake_Charges_Send" UniqueName="Fake_Charges_Send" ItemStyle-CssClass="grid_txt_NO" ColumnEditorID="GridTextBoxColumn"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="TemplateEditColumn"> <ItemTemplate> <asp:HyperLink ID="EditLink" runat="server" ToolTip="افزايش شارژ" ImageUrl="../Images/Icons/Credit.png" Text="Charge"></asp:HyperLink> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> <PagerStyle Mode="NumericPages" /> <EditFormSettings ColumnNumber="3" CaptionDataField="PanelId" CaptionFormatString="ويرايش اطلاعات" InsertCaption="" FormCaptionStyle-Font-Names="Tahoma" FormStyle-Font-Names="Tahoma"> <FormTableItemStyle Wrap="True"></FormTableItemStyle> <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> <FormMainTableStyle GridLines="None" CellSpacing="5" BorderColor="Yellow" CellPadding="3" Width="100%" /> <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" Font-Names="Tahoma" /> <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> <EditColumn ButtonType="ImageButton" InsertText="ثبت " UpdateText="ويرايش" UniqueName="EditCommandColumn1" CancelText="لغو "> </EditColumn> <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle> </EditFormSettings> </MasterTableView> <ClientSettings> <Selecting AllowRowSelect="true" /> <ClientEvents OnRowDblClick="RowDblClick" /> </ClientSettings> </telerik:RadGrid> <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" OnClientClose="refreshGrid" > <Windows> <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Height="320px" Width="310px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" /> </Windows> </telerik:RadWindowManager> <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumn" runat="server" TextBoxStyle-CssClass="GridTextBoxColumnEditor" /> <asp:Label ID="Label1" runat="server" Width="410px"></asp:Label> </div> <!-- content end --> </form></body></html>protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink"); editLink.Attributes["href"] = "#"; editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PanelId"], e.Item.ItemIndex); } }protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) { if (e.Argument == "Rebind") { RadGrid1.MasterTableView.SortExpressions.Clear(); RadGrid1.MasterTableView.GroupByExpressions.Clear(); RadGrid1.Rebind(); } else if (e.Argument == "RebindAndNavigate") { RadGrid1.MasterTableView.SortExpressions.Clear(); RadGrid1.MasterTableView.GroupByExpressions.Clear(); RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1; RadGrid1.Rebind(); } }<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditFormCS.aspx.cs" Inherits="UserControls_EditFormCS" %><!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 id="Head1" runat="server"> <title>Edit dialog</title></head><body> <form id="form1" runat="server"> <div> <script type="text/javascript"> function CloseAndRebind(args) { GetRadWindow().BrowserWindow.refreshGrid(args); GetRadWindow().close(); } function GetRadWindow() { var oWindow = null; if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well) return oWindow; } function CancelEdit() { GetRadWindow().close(); } function onError(input, args) { var message = "Invalid character: "; message += "accepts only numberic values."; document.getElementById("numInput").innerHTML = args.get_inputText(); document.getElementById("numErrorOut").innerHTML = message; } function onKeyPress(input, args) { document.getElementById("numInput").innerHTML = ""; document.getElementById("numErrorOut").innerHTML = ""; } function Close() { GetRadWindow().Close(); } </script> <asp:ScriptManager ID="ScriptManager2" runat="server" /> <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" /> <br /> <br /> <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Type="Number" NumberFormat-DecimalDigits="0"> <ClientEvents OnError="onError" OnKeyPress="onKeyPress"></ClientEvents> </telerik:RadNumericTextBox> <asp:Button runat="server" Text="Submit" ID="btnSubmit" OnClick="Unnamed1_Click" /> <asp:Button runat="server" Text="Reset" ID="btnReset" OnClick="btnReset_Click" Visible="false" /> </div> <asp:Label ID="Label1" runat="server" Width="410px"></asp:Label> <div class="module" style="width: 448px; clear: both;"> <table cellpadding="4" cellspacing="0" width="100%"> <tbody> <tr> <td> <span id="numInput"></span> </td> <td> <span id="numErrorOut" style="color: Red"></span> </td> </tr> </tbody> </table> </div> </form></body></html>protected override void OnInit(EventArgs e) { base.OnInit(e); this.Page.Title = "Editing record"; }protected void btnSubmit_Click(object sender, EventArgs e) { //Some Code here Label1.Text = "<script type='text/javascript'>Close()</" + "script>"; } } protected void btnReset_Click(object sender, EventArgs e) { /SomeCode here }