Reputation: 325
I have a RadGrid on my parent page with a GridTemplateColumn that contains a asp hyperlink field. In the ItemDataBound event of the grid I was doing the following to open up a page inside of a RadWindow (the page inside the window took care of all of the logic):
hyperlink.Attributes.Add("onclick", string.Format("openDialogWindow({0}, '{1}', '{2}');", productId, categoryId, typeId));
This is the JavaScript function used to open the page inside the window:
function openDialogWindow(productId, categoryId, typeId) {
openRadWindow("DialogPage.aspx?ProductId=" + productId + "&CategoryId=" + categoryId + "&TypeId=" + typeId, "dialog title", 800, 600);
}
Instead of doing it this way I prefer adding a RadWindow on my parent page with a user control inside of its content template. The user control will display everything that the DialogPage.aspx did. The parent page will set all necessary properties of the control (productId, categoryId, typeId) so when the window opens the proper information will display depending on which cell of the grid they click the hyperlink button on.
Is something like this possible? Or is creating a separate page that opens in a RadWindow and passing query string params to it the best way to do it. This is how I currently have it.
Upvotes: 0
Views: 2287
Reputation: 11154
Please try with the below code snippet.
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TelerikWebApp1.WebForm1" %>
<%@ Register TagPrefix="uc" TagName="usercontrol" Src="~/WebUserControl1.ascx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
</script>
</telerik:RadCodeBlock>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="RadWindow1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadWindow ID="RadWindow1" runat="server">
<ContentTemplate>
<uc:usercontrol ID="usercontrol1" runat="server" />
</ContentTemplate>
</telerik:RadWindow>
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
AutoGenerateColumns="false">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace TelerikWebApp1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object source, System.EventArgs e)
{
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name ="Name2"} };
RadGrid1.DataSource = data;
}
protected void Button1_Click(object sender, EventArgs e)
{
Button Button1 = sender as Button;
GridDataItem item = Button1.NamingContainer as GridDataItem;
string strID = item["ID"].Text;
(usercontrol1.FindControl("Label1") as Label).Text = strID;
RadWindow1.VisibleOnPageLoad = true;
}
}
}
WebUserControl1.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="TelerikWebApp1.WebUserControl1" %>
<asp:Label ID="Label1" runat="server"></asp:Label>
Let me know if any concern.
Upvotes: 1