i have a main page called view.ascx.
this page contains a radmultipage control. this control also contains some radpageviews.
on one of these radpageview reference another page called effects.ascx which contains some radgrids.
the first radgrid radgrid1 contains a edit button. when i click this button a editformtemplate opens. these editformtype is a webusercontrol (filename = control1.ascx). these webusercontol contains a button.
if i click on this button a second radgrid appears on my effects.ascx. these radgrid has a select button.
now when i click on this button, i want to set the value of the selected row to my textbox in the control1.ascx.
i hope to get some solution to sort my problem out.
Thanks
Chris
3 Answers, 1 is accepted
To achieve the desired functionality I suggest you review the following link:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/accessing-server-controls-in-a-grid-template-on-the-client.aspx
Kind regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
i've red the link carefully, but i noticed that the main problem is, that i dont work with autogeneradted edit forms. i use a usercontrol to edit my data and i couldnt get access to my usercontrol.
well i ll post my project, in hope, you could ll find a solution to sort my problem out.
Default.ascx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<%@ Register src="~/WebUserControl.ascx"tagname="Web" tagprefix="uc1" %> |
<!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> |
asd |
<form id="form1" runat="server"> |
<asp:ScriptManager ID="ScriptManager1" runat="server"> |
</asp:ScriptManager> |
<telerik:RadMultiPage ID="RadMultiPage1" Runat="server" SelectedIndex="0"> |
<telerik:RadPageView ID="RadPageView1" runat="server"> |
|
<uc1:Web runat="server" /> |
|
|
<br /> |
|
<br /> |
|
</telerik:RadPageView> |
</telerik:RadMultiPage> |
</form> |
</body> |
</html> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using Telerik.Web.UI; |
public partial class _Default : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
} |
UserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> |
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> |
<form id="form1"> |
<div> |
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ObjectDataSource1" |
GridLines="None" AutoGenerateEditColumn="True"> |
<MasterTableView autogeneratecolumns="False" datakeynames="appointmentID" |
datasourceid="ObjectDataSource1"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="appointmentID" DataType="System.Int32" |
HeaderText="appointmentID" ReadOnly="True" SortExpression="appointmentID" |
UniqueName="appointmentID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="name" HeaderText="name" |
SortExpression="name" UniqueName="name"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="location" HeaderText="location" |
SortExpression="location" UniqueName="location"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="description" HeaderText="description" |
SortExpression="description" UniqueName="description"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="date" DataType="System.DateTime" |
HeaderText="date" SortExpression="date" UniqueName="date"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="userID" DataType="System.Int32" |
HeaderText="userID" SortExpression="userID" UniqueName="userID"> |
</telerik:GridBoundColumn> |
</Columns> |
<editformsettings editformtype="WebUserControl" |
usercontrolname="EditTemplate.ascx"> |
</editformsettings> |
</MasterTableView> |
</telerik:RadGrid> |
</div> |
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" |
DeleteMethod="Delete" InsertMethod="Insert" |
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" |
TypeName="DataSet1TableAdapters.appointmentsTableAdapter" UpdateMethod="Update"> |
<DeleteParameters> |
<asp:Parameter Name="Original_appointmentID" Type="Int32" /> |
</DeleteParameters> |
<UpdateParameters> |
<asp:Parameter Name="name" Type="String" /> |
<asp:Parameter Name="location" Type="String" /> |
<asp:Parameter Name="description" Type="String" /> |
<asp:Parameter Name="date" Type="DateTime" /> |
<asp:Parameter Name="userID" Type="Int32" /> |
<asp:Parameter Name="Original_appointmentID" Type="Int32" /> |
</UpdateParameters> |
<InsertParameters> |
<asp:Parameter Name="name" Type="String" /> |
<asp:Parameter Name="location" Type="String" /> |
<asp:Parameter Name="description" Type="String" /> |
<asp:Parameter Name="date" Type="DateTime" /> |
<asp:Parameter Name="userID" Type="Int32" /> |
</InsertParameters> |
</asp:ObjectDataSource> |
<asp:Label ID="Label1" runat="server" Text="10"></asp:Label> |
</form> |
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
public partial class WebUserControl : System.Web.UI.UserControl |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
protected void Button1_Click(object sender, EventArgs e) |
{ |
//How can i get access to the RadGrid1.EditFormTemplate.TextBox1 |
} |
} |
EditTemplate.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EditTemplate.ascx.cs" Inherits="EditTemplate" %> |
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> |
<br /> |
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Web; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
public partial class EditTemplate : System.Web.UI.UserControl |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
protected void Button1_Click(object sender, EventArgs e) |
{ |
TextBox1.Text = (Parent.Parent.Parent.Parent.Parent.Parent.Parent.FindControl("Label1") as Label).Text; |
} |
} |
The Problem is about the EditFormTemplate.
I want to set the Text of the TextBox1.
There are two button on that page. On button is on the EditFormTemplate.ascx placed. If you look at the Button1_Click(...), u ll see that i set the text of the TextBox1 in the EditFormTemplate with the Text of the Label1 from WebUserControl.ascx. Because of the Controlhierarchy i have to navigate through the controls by parent.parent..... and so on. Is there another more effecient appraoch to manage that????
the other thing is how to set the Text of the Textbox1(EditFormTemplate) by clicking on a button Button1 on the WebUserControl.ascx. How can i do that?? Coulnt find a solution to get access to my UserControl inside the radGrid1 via the WebControl.ascx.
i only want to set the Text in the Textbox by calling the method Button1_Click() in WebUserControl.ascx.
Kind regards,
Chris
You can access the user control through the GridDataItem object:
((Telerik.Web.UI.GridDataItem)(e.Item)).EditFormItem.FindControl("NameOfYourUserControl") |
I hope this helps. Let me know if you need further assistance.
All the best,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.