More in this section

Forums / General Discussions / Custom Module ViewState

Custom Module ViewState

6 posts, 1 answered
  1. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    17 Apr 2011
    Link to this post
    Hi,

    I am creating a custom module and it is starting to take shape.  As part of the paging solution i am working on, i am using a combo box to handle the paging side (the selected index change event redirects with the page no).

    Anyway, i think my issue is caused becuase i am using a ListView and the databinding is happening at different times (i.e. the event handler for my combobox is running before the page controls are being rebound or something similar).  I have tried a few different things and cant seem to get it to do anything, can someone please have a look?

    protected override void InitializeControls(GenericContainer container)
    {
        rcbPager.AutoPostBack = true;
        rcbPager.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(rcbPager_SelectedIndexChanged);
    }
     
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        this.ddlPager.AutoPostBack = true;
        this.ddlPager.SelectedIndexChanged += new EventHandler(ddlPager_SelectedIndexChanged);
    }
     
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
     
        if (!Page.IsPostBack)
        {
            LoadData();
        }
    }
     
    protected override string LayoutTemplateName
    {
        get { return this.layoutTemplateName; }
    }
     
    private void LoadData()
    {
        var Request = Page.Request;
        int count = 0;
     
        string material = Request.Params["material"] != null ? Request.Params["material"].ToString() : "";
        int type = Request.Params["type"] != null ? Convert.ToInt32(Request.Params["type"]) : 0;
        string finish = Request.Params["finish"] != null ? Request.Params["finish"].ToString() : "";
        string colour = Request.Params["colour"] != null ? Request.Params["colour"].ToString() : "";
        string thickness = Request.Params["thickness"] != null ? Request.Params["thickness"].ToString() : "";
        int pageNo = Request.Params["page"] != null ? Convert.ToInt32(Request.Params["page"].ToString()) : 1;
         
        var manager = new BlocksManager();
        var list = manager.GetSlabs(material, type, finish, colour, thickness, pageNo, 3, out count);
     
        if (count > 0)
        {
            lvSlabs.DataSource = list;
            lvSlabs.DataBind();
        }
        else
             litMessage.Text = string.Format("<p>{0}</p>", "Your search returned no records");
     
     
        //Setup Pager Items
        BuildPagerItems(count);
    }
     
    private void BuildPagerItems(int count)
    {
        if (rcbPager.Items.Count == 0)
        {
            int pages = (int)Math.Ceiling((float)count / 3);
     
            for (int i = 0; i < pages; i++)
            {
                //ddlPager.Items.Add(new ListItem(string.Format("page {0} of {1}", (i + 1).ToString(), pages.ToString())));
                rcbPager.Items.Add(new RadComboBoxItem(string.Format("page {0} of {1}", (i + 1).ToString(), pages.ToString(), (i + 1).ToString())));
            }
        }
    }
     
    protected void rcbPager_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        string prefix = "?";
     
        if (Page.Request.QueryString.Keys.Count > 0)
            prefix = "&";
     
        Page.Response.Redirect(Page.Request.Url.ToString() + string.Format("{0}page={1}", prefix, rcbPager.SelectedValue));
    }
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    17 Apr 2011
    Link to this post
    There should be the 4.1 update tomorrow or tuesday which should fix the Viewstate issues we're all having :)

    If you believe it to be a Viewstate issue, wait for that update before beating your head against a wall.

    Steve
  3. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    18 Apr 2011
    Link to this post
    Hi Steve,

    Yeah i have been beating my head against some walls with SF 4 :) i will wait for the update, hopefully that will help me out. Not sure what is happening though as the SDK examples surely work, so why woudnt my ViewState??? hmmm.

    Rob
  4. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    18 Apr 2011
    Link to this post
    Hi,

    Can someone over at telerik have a look at my code and make sure this is a viewstate issue and not something else.  I needed to bind data in the pre_render method as i was recieving control errors when doing it anywhere else, i also know there is a postback check in there but this was happening with or without that code.

    If this is a viewstate issue i will have to wait for the update, but if not i would like to get moving with it.

    Rob
  5. Teodor
    Teodor avatar
    52 posts
    Registered:
    24 Sep 2012
    20 Apr 2011
    Link to this post
    Hello Roberto Modica,


         Are you having the same problem with the latest version of sitefinity? Can you provide more information about the errors witch you receive ?

    Kind regards,
    Teodor
    the Telerik team

    Answered
  6. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    20 Apr 2011
    Link to this post
    Hi Teodor ,

    Maybe 4.1 did something but there was my fault in my code aswell as i was missing something which i corrected and it seems to be working now.

    Thanks for looking into this for me anyway.

    Rob
6 posts, 1 answered