1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Redirect to custom Page from SimpleControl

Redirect to custom Page from SimpleControl

5 posts, 2 answered
  1. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    07 Jan 2010
    Link to this post
    Hello,

    I have one problem with redirect to a custom page in a simple control:

    I´m in the next scenary:

    I have a ControlCustomBase inherit of Telerik.Cms.Web.UI.SimpleControl.

    this is a control view to toolboxcontrols in sitefinity...

    I would like redirect with (X).Respones.Redirect("~/page.aspx") but i do:

    HttpContext.Current.Response.Redirect("~/page.aspx"); (Not work)
    this.Page.Response.Redirect("~/page.aspx"); (Not work)
    this.Context.Response.Redirect("~/page.aspx"); (Not work)
    this.Container.Page.Response.Redirect("~/page.aspx"); (Not work)
    ((Page)this.Container.Parent).Response.Redirect("~/page.aspx"); (Not work)

    I not know that i can do...

    Can you help me please?

    Thanks.

    Salu2,
    Pablo


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Jan 2010
    Link to this post
    Hello xax_007,

    Can you share some more code? Where actually you are trying to make the redirect - are you click any button or inside any method or event. Generally this should work without problems.

    this.Page.Response.Redirect("http://www.domain.com");


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    07 Jan 2010
    Link to this post
    //BASE
    namespace LittleView  
    {  
        [ControlDesigner(typeof(LittleDesignerCustom))]  
        public class LittleViewCustomBase : SimpleControl  
        {      
            /// <summary>  
            /// Obtiene o establece la direccion url a la que navegar  
            /// </summary>  
            public String NavigationUrl { getset; }  
     
     
        }  
     
          
     

    Custom

    namespace LittleView  
    {  
        public class LittleViewCustom: LittleViewCustomBase  
        {        
            public override string LayoutTemplatePath  
            {  
                get 
                {  
                      return "~/Sitefinity/Admin/ControlTemplates/MyTemplates/LittleView.ascx";  
                }  
            }  
     
            public LittleViewCustom()  
            {  
                //Capturamos los eventos en el constructor  
                PreRender += new EventHandler(ViewCustom_PreRender);  
            }  
     
     
            void ViewCustom_PreRender(object sender, EventArgs e)  
            {  
                Repeater1.ItemCommand += new RepeaterCommandEventHandler(Repeater1_ItemCommand);  
                Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);  
                  
                    String dafault = String.Empty;  
     
                    if (this.Page != null && this.Page.Session["dafault"] != null)  
                    {  
                        dafault = this.Page.Session["dafault"].ToString();  
                    }  
     
                    WebSERVICE.WSData clientData = new WebSERVICE.WSData();  
     
                    Repeater1.DataSource = clientData .GetDATA();  
     
                    Repeater1.DataBind();  
     
                }  
              
     
            void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)  
            {  
                LinkButton lB = e.Item.FindControl("goto"as LinkButton;  
     
                lB.Click +=new EventHandler(lB_Click);  
                  
                //lB.PostBackUrl = this.NavigationUrl;  
     
            }  
     
            void lB_Click(object sender, EventArgs e)  
            {  
                this.Page.Session["default"] = ((LinkButton)sender).CommandArgument;  
                this.Page.Response.Redirect(this.NavigationUrl);  
            }  
     
              
     
            void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)  
            {  
     
                this.Page.Session["default"] = ((WebSERVICE.Data)e.Item.DataItem).Id;  
                this.Page.Current.Response.Redirect(this.NavigationUrl);  
     
     
     
     
     
            }  
     
     
     
            //Referenciamos el literal de parametros de inicio del ascx asociado  
            public virtual Repeater Repeater1  
            {  
                get 
                {  
                    return this.Container.GetControl<Repeater>("Repeater1"true);  
                }  
            }  
        }  


    ASCX

    <%@ Control Language="C#" %> 
     
    <asp:Repeater id="Repeater1" runat="server" > 
                
              <ItemTemplate > 
                
                 <table> 
                    <tr> 
                       <b> 
                          <asp:LinkButton ID="goto" Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'   
                          runat="server"   
                          CommandName="goto"   
                          CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' 
                                                
                          /> 
                          <asp:Label runat="server" ID="vamos" /> 
                       </b> 
                    </tr> 
                    <tr> 
                       <%# DataBinder.Eval(Container.DataItem, "Description") %> 
                    </tr> 
                    <tr> 
                    </tr> 
                 </table> 
              </ItemTemplate> 
     
           </asp:Repeater> 


    If i need Response.Redirect && Session for work correctly...

    in Repeater1_ItemCommand not work
    in  lB_Click not work

    There are any solution?

    Thanks Ivan

    Salu2,
    Pablo

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Jan 2010
    Link to this post
    Hello xax_007,

    1. You do not have to use InitializeControls instead of PreRender.
    2. You have to alter Repeater1_ItemDataBound event and check for the ListItemType.

    Below is a sample code that works without problems at my end

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    using System.Collections;
     
    /// <summary>
    /// Summary description for SimpleControlCustom
    /// </summary>
    public class SimpleControlCustom : SimpleControl
    {
        public SimpleControlCustom()
        {
     
        }
     
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/CustomControls/SimpeControlTemplate.ascx";
            }
     
        }
     
        protected override void InitializeControls(System.Web.UI.Control controlContainer)
        {
            base.InitializeControls(controlContainer);
     
            var manager = new ContentManager("News");
            IList datasource = manager.GetContent();
     
            this.Repeater1.DataSource = datasource;
            this.Repeater1.ItemDataBound += new RepeaterItemEventHandler(Repeater1_ItemDataBound);
            this.Repeater1.DataBind();
        }
     
        void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                IContent cnt = (IContent)e.Item.DataItem;
                Label label = (Label)e.Item.FindControl("Label1");
                LinkButton button = (LinkButton)e.Item.FindControl("LinkButton1");
                if (label != null && button !=null)
                {
                    label.Text = (string)cnt.GetMetaData("Title");
                    button.Click += new EventHandler(button_Click);
                }
            }
        }
     
        void button_Click(object sender, EventArgs e)
        {
            this.Page.Response.Redirect("http://www.google.com");
        }
     
        public virtual Repeater Repeater1
        {
            get
            {
                return this.Container.GetControl<Repeater>("Repeater1", true);
            }
        
    }

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="SimpeControlTemplate.ascx.cs" Inherits="CustomControls_SimpeControlTemplate" %>
     
     
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" ></asp:Label>
            <asp:LinkButton ID="LinkButton1" runat="server" Text="Click" ></asp:LinkButton>
        </ItemTemplate>
    </asp:Repeater>


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  5. xax_007
    xax_007 avatar
    55 posts
    Registered:
    24 Jul 2009
    07 Jan 2010
    Link to this post
    Ok Ivan, work perfect,

    Maybe pre_render is not valid for this.

    Thanks very much.

    Salu2,
    Pablo
Register for webinar
5 posts, 2 answered