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

Forums / Bugs & Issues / Custom User Controls, Page Refreshing

Custom User Controls, Page Refreshing

8 posts, 0 answered
  1. D
    D avatar
    9 posts
    Registered:
    05 Jun 2009
    27 Jul 2009
    Link to this post
    Hello All,

    I'm making a lot of progress migrating an old iBuySpy page up to Sitefinity, but have run into a bit of a brick wall. There were a number of user controls that had menus (drop-downs, radio buttons, etc) for the purposes of pulling database data and displaying tables.

    Now, I was able to get it to link to the database just fine, so now there's the connection to the SiteFinity DB and the connection to the old DB for these controls.. that part's not an issue, thankfully.

    What I -am- having trouble with is the controls themselves. The parts of the menu have OnSelect commands, but selecting anything causes the entire page to refresh and all parts of the form to revert to their default values. The expected behavior is that the selected item remains as-is, and the rest of the form runs through its logic to adjust other pulldowns (such as selecting a state -> populating a drop-down of cities).

    For example, a SELECT tag in one of the forms looks like this:
    <select name="ctl00$contentZone$ctl00$AssessorsDropDownList" onchange="javascript:setTimeout('__doPostBack(\'ctl00$contentZone$ctl00$AssessorsDropDownList\',\'\')', 0)" id="ctl00_contentZone_ctl00_AssessorsDropDownList">  
    ...
     

    In its previous iBuySpy implementation, the same SELECT tag looked like this:
    <select name="_ctl4:AssessorsDropDownList" onchange="__doPostBack('_ctl4$AssessorsDropDownList','')" language="javascript" id="_ctl4_AssessorsDropDownList"

    ...

    I'm not sure why, or if, or how, Sitefinity chose to modify this user control when it was uploaded. If anyone has any particular insight into the perils of uploading user controls, I'm all ears.

    Also, if this is insuffecient information, I'm always happy to dig up more to try and get you what you need to know, so I know what I need to know! Ask away.

    As always, I appreciate everyone's help here.
    -D
  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    21 Nov 2016
    29 Jul 2009
    Link to this post
    Hello D,

    Can you try to add your old controls directly to the master page file instead of uploading them to Sitefinity. Also enable the view state for the Sitefinity page just in case you have disable it.

    Kind regards,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. D
    D avatar
    9 posts
    Registered:
    05 Jun 2009
    31 Jul 2009
    Link to this post
    Nikolai,

    I've verified that the pages do in fact have ViewState enabled, so that wasn't it.

    As for creating a @register in a master page and setting that master page to the specific page in question, that's a highly impractical way to go about it. I've, unfortunately, got hundreds of these user controls to bind to pages, and on top of the problem of having to create and upload hundreds of master pages, I'd have to redo the master page every time I wanted to add or remove one user control.

    I've read online that there is a way to dynamically add user controls. Something along the lines of:

    C#
    Control NameOfUserControl = LoadControl("~/directory/structure/thecontrolfile.ascx");
    PlaceHolderName.Controls.Add(NameOfUserControl);

    Of course, that presents the fresh problem of, how would one add -that- code to a page?
  4. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    21 Nov 2016
    03 Aug 2009
    Link to this post
    Hello D,

    We are still not exactly sure why this is happening.
    About your solution on adding controls dynamically, can you tell us if the following works for you:
    1. Create new "[SomeControlName].ascx" control in Visual Studio
    2. Set one "PlaceHolder" inside that control. Should look like this:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="[YourControlName].ascx.cs" Inherits="[YourControlName]" %> 
     
    <asp:PlaceHolder ID="placeHolder" runat="server"
     
    </asp:PlaceHolder> 
    3. Open the code-behind file and create one property "ControlPath":
    public string ControlPath { getset; } 
    4. On "Page_Load" event set your code like this:
    protected void Page_Load(object sender, EventArgs e) 
        { 
            Control NameOfUserControl = LoadControl(this.ControlPath); 
            this.placeHolder.Controls.Add(NameOfUserControl); 
        } 

    5. Save and upload to Sitefinity via the "Controls Uploader" inside the page editor.
    This way when you drag&drop the new control on the page in its edit mode, there will be property called "ControlPath" in which you can select the path to a external control(for example ~/UserControls/DummiControl.ascx).

    Regards,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  5. D
    D avatar
    9 posts
    Registered:
    05 Jun 2009
    03 Aug 2009
    Link to this post
    Well, this has definitely been a point of progress, so for as far as I've gotten so far, thanks. =)

    I think I've pretty conclusively settled that something's oddball about how my Sitefinity site is handling OnEvents. I wrote your very awesome user control, used it to bind with one of the controls, and though it didn't come through perfectly, it did come through, which is a start, and a much better way to implement the solution than manually adding every single user control into the Add Controls dialog.

    The problem is, it still had the same problem with events.. any postback of any kind forced it to reload with default values.

    I'll show you the simple code I wrote to test this:

    DropdownTest.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropdownTest.aspx.cs" Inherits="DropdownTest" %> 
    <%@ Register Src="~/DropdownTest.ascx" TagName="DropdownTest" TagPrefix="test" %> 
     
    <!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>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
           <test:DropdownTest runat="server" id="Control1"></test:DropdownTest> 
        </div> 
        </form> 
    </body> 
    </html> 
     

    DropdownTest.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="DropdownTest.ascx.cs" Inherits="DropdownTest" %> 
     
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
        <asp:ListItem>Bagel</asp:ListItem> 
        <asp:ListItem>Toast</asp:ListItem> 
        <asp:ListItem>Nothing</asp:ListItem> 
    </asp:DropDownList> 
     
    <asp:DropDownList ID="DropDownList2" runat="server"
    </asp:DropDownList> 
     

    DropdownTest.ascx.cs
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Collections; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
     
    public partial class DropdownTest : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
        } 
     
        protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged); 
        } 
     
        void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            DropDownList2.Items.Add(new ListItem("New Item")); 
        } 
     


    Now, executed on its own, this code creates a very simple page with two drop-down menus. The first one contains three values, and when one is selected, the page reloads and populates the second dropdown with a value. Viewed in the aspx page, this works fine. Uploaded as a user control to Sitefinity and added to a page, this does not work. It has the same behavior.. reloads the form with the default value (Bagel) in the first dropdown and nothing in the second. Even using your most excellent Import Control to run this results in this behavior.

    Honest to goodness, I'm stumped. Is Sitefinity somehow predisposed to listening for events, and it's catching them before my user control can properly handle them?
  6. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    21 Nov 2016
    06 Aug 2009
    Link to this post
    Hello D,

    Based on your page and control that you sent, we didn't manage to reproduce the problem today.
    No matter how we used the code either as classic "ascx" or "Sitefinity" control the second combo box items are created on "PostBack".
    Sitefinity does not suppress or catch any events raised by the controls on the page. The only place that links are forbidden is  the simple page preview "IFrame" in the "Pages" section.


    Kind regards,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  7. D
    D avatar
    9 posts
    Registered:
    05 Jun 2009
    07 Aug 2009
    Link to this post
    Nikolai,

    I managed to find the culprit - something is wrong with my self-coded header.ascx control. Either the search box, or the login box, must be breaking the rest of the page somehow, because when I exclude the header from the page, the imported form works (mostly) correctly.

    The header uses the generic ASP.NET login control, and the Sitefinity search box control.
  8. D
    D avatar
    9 posts
    Registered:
    05 Jun 2009
    07 Aug 2009
    Link to this post
    Tada. Header had a <form>, conflicting with the rest of the page what with the auto-generated Sitefinity <form> tag, ergo, kaboom. Peachy. Now I just have to debug these hundred-and-change user controls, but that's no fault of Sitefinity.

    Thanks for all the help. =)
Register for webinar
8 posts, 0 answered