Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
221 views
Hello,

How can one from a UserControl which dynamically created, close itself and open another UserControl dynamically?

Update:I solved this after some searching. I have updated my post with code that worked for me. It is not tidy. Someone may have a smarter solution?

default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            //Put your JavaScript code here.
        </script>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RibbonBarButton1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="PlaceHolder1" />
                        <telerik:AjaxUpdatedControl ControlID="hf" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RibbonBarButton2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="PlaceHolder1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="hf" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <div>
 
 
            <telerik:RadRibbonBar ID="RadRibbonBar1" runat="server" Width="900px" Style="max-width: 900px;" Skin="Office2010Silver" EnableMinimizing="true">
                <telerik:RibbonBarTab Text="UC">
                    <telerik:RibbonBarGroup Text="UC1" ID="RibbonBarGroup1">
                        <Items>
 
                            <telerik:RibbonBarButton Size="Large" Text="UC1" ImageUrlLarge="/images/icons/docs_32.png" ID="RibbonBarButton1" />
 
                        </Items>
                    </telerik:RibbonBarGroup>
                    <telerik:RibbonBarGroup Text="UC2" ID="RibbonBarGroup2">
                        <Items>
 
                            <telerik:RibbonBarButton Size="Large" Text="UC2" ImageUrlLarge="/images/icons/docs_32.png" ID="RibbonBarButton2" />
 
                        </Items>
                    </telerik:RibbonBarGroup>
                </telerik:RibbonBarTab>
            </telerik:RadRibbonBar>
 
 
 
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </div>
        <asp:Label ID="hf" Text="" runat="server" Visible="false" />
    </form>
</body>
</html>


default.aspx.vb
Imports Telerik.Web.UI
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
 
    Protected Sub RadRibbonBar1_ButtonClick(sender As Object, e As RibbonBarButtonClickEventArgs) Handles RadRibbonBar1.ButtonClick
 
        If e.Button.ID.ToString = "RibbonBarButton1" Then
            LoadUserControl("UC1")
        ElseIf e.Button.ID.ToString = "RibbonBarButton2" Then
            LoadUserControl("UC2")
        End If
 
            End Sub
 
    Public Sub LoadUserControl(ByVal userControl As String)
 
        hf.Text = userControl
 
        PlaceHolder1.Controls.Clear()
 
        Dim wuc As Web.UI.UserControl = CType(LoadControl("~/" & userControl & ".ascx"), Web.UI.UserControl)
        wuc.ID = userControl
        PlaceHolder1.Controls.Add(wuc)
 
    End Sub
 
 
 
 
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
 
        If Page.IsPostBack Then
 
            If hf.Text.Length > 2 Then
 
                Dim wuc As Web.UI.UserControl = CType(LoadControl("~/" & hf.Text & ".ascx"), Web.UI.UserControl)
 
                wuc.ID = hf.Text
                wuc.Visible = False
                PlaceHolder1.Controls.Add(wuc)
            End If
        End If
 
    End Sub
End Class


UC1.ascx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="UC1.ascx.vb" Inherits="UC1" %>
 
UC1<br />
<asp:Button ID="Button1" runat="server" Text="Open UC2" />
UC1.ascx.vb
Partial Class UC1
    Inherits System.Web.UI.UserControl
 
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' show the other control
        Dim wuc As Web.UI.UserControl = CType(LoadControl("~/UC2.ascx"), Web.UI.UserControl)
        Dim holder As PlaceHolder = CType(ControlExtensions.FindControlRecursive(Page, "PlaceHolder1"), PlaceHolder)
 
        wuc.ID = "UC2"
        wuc.Visible = True
 
        holder.Controls.Add(wuc)
 
        Dim hf As Label = CType(ControlExtensions.FindControlRecursive(Page, "hf"), Label)
        hf.Text = "UC2"
    End Sub
End Class

UC2.ascx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="UC2.ascx.vb" Inherits="UC2" %>
 
UC2<br />
<asp:Button ID="Button1" runat="server" Text="Open UC1" />
UC2.ascx.vb
Partial Class UC2
    Inherits System.Web.UI.UserControl
 
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' show the other control
        Dim wuc As Web.UI.UserControl = CType(LoadControl("~/UC1.ascx"), Web.UI.UserControl)
        Dim holder As PlaceHolder = CType(ControlExtensions.FindControlRecursive(Page, "PlaceHolder1"), PlaceHolder)
 
        wuc.ID = "UC1"
        wuc.Visible = True
 
        holder.Controls.Add(wuc)
 
        Dim hf As Label = CType(ControlExtensions.FindControlRecursive(Page, "hf"), Label)
        hf.Text = "UC1"
    End Sub
End Class

ControlExtensions.vb
Imports Microsoft.VisualBasic
 
Public Class ControlExtensions
 
    ''' <summary>
    ''' recursively finds a child control of the specified parent.
    ''' </summary>
    ''' <param name="control"></param>
    ''' <param name="id"></param>
    ''' <returns></returns>
    Public Shared Function FindControlRecursive(ByVal control As Control, ByVal id As String) As Control
        If control Is Nothing Then
            Return Nothing
        End If
 
        'try to find the control at the current level
        Dim ctrl As Control = control.FindControl(id)
 
        If ctrl Is Nothing Then
            'search the children
            For Each child As Control In control.Controls
                ctrl = FindControlRecursive(child, id)
                If Not ctrl Is Nothing Then
                    Exit For
                End If
            Next child
        End If
 
        Return ctrl
    End Function
 
 
End Class


/Janne
Maria Ilieva
Telerik team
 answered on 13 Sep 2012
1 answer
402 views
Is it possible to find grid bound column in grid prerender event of radgrid. I am trying to select the first row of radgrid on page load and display the values of selected row in second grid. Is there any other way to achieve rather than accessing the column i prerender event
Shinu
Top achievements
Rank 2
 answered on 13 Sep 2012
1 answer
135 views
Hi,

I'm following the GridAttachmentColumn demo and saving to the database - all works well, but in the demo, if no file is uploaded the error message is added like so:-

  RadGrid1.Controls.Add(New LiteralControl("<b style='color:red;'>No file uploaded. Action canceled.</b>"))

This puts the message right at the bottom of the grid - is there a way to show it within the auto generated edit form please?

Also, I did look but is there an example of the GridAttachmentColumn using an edit form template?

Cheers,

Jon

Martin
Telerik team
 answered on 13 Sep 2012
4 answers
48 views
In your demo URL

http://demos.telerik.com/aspnet-ajax/editor/examples/settingcontentareadefaults/defaultcs.aspx

When i Select ContentAreaMode as "DIV" and typed the continuous letter without any space/Break then RadEditor's width increases.

But if have it in IFrame mode and typed the continuous letters then once reached end of rad editor it automatically wrapped.

Above is my current requirement, so please help me to solve this issue.

Also see attached image for reference.


Thanks,
Jawahar.
jawahar
Top achievements
Rank 1
 answered on 13 Sep 2012
2 answers
162 views
hi,
kindly help me .
how to reduce options in filter menu in rad grid according to column type from server side ?
Ashraf
Top achievements
Rank 2
 answered on 13 Sep 2012
5 answers
75 views
RadGrid won't go into Edit mode -

I just installed RadControls for ASP.NET AJAX on my Windows XP 32bit development PC with VS 2010.

I opened a newly created website which had only a single GridView already on it and I selected Convert to Telerik web site from the Telerik menu that is now in VS.

The first thing I noticed was that the GridView no longer worked.  Clicking on Select or Edit no longer do anything.  So I dragged a RadGrid to the form, left all the default settings and selected the same DataSource the original GridView is using.  Now with the original GridView and the new RadGrid on the page, both grids display the same rows of data as one would expect. 

I enabled AllowAutomaticDeletes, AllowAutomaticInserts, and AllowAutomaticUpdates and set AutoGenerateEditColumn to True.

The original GridView still does not work.  Click "Select" and the row is not selected.  Click "Edit" and it does not go into Edit mode.
The new RadGrid also does not work.  There is an "Edit" link.  Clicking it does nothing.  The page flickers like there was a postback or something, but the row does not go into edit mode.

I started with the standard ToolkitScriptManager and then changed it to the RadScriptManager.  Neither worked.

What am I missing?
Radoslav
Telerik team
 answered on 13 Sep 2012
1 answer
73 views
I have a detail table with a ParentTableRelation setup. The child rows are displaying and filtering for the parent record, I want to be able to add new rows where the newly inserted row includes the ID of the parent into it's forgein key. I had thought that setting up a ParentTableRelation might automatically do this, but saving fails due to the forgein key not being supplied.

Are there any examples of this?

If there's no simple way to do this I could always set a hidden field when the row is created. 

Martin
Telerik team
 answered on 13 Sep 2012
1 answer
44 views
hi

When i apply sorting on telerik grid column

one column has got empty values ,so on sorting ascending on that cloumn empty values are coming on top

(Empty items has higher precedence than an item starting with  "A")

how to avoid this in telrik grid sorting

i want item with empty values to go at the bottm in both Ascending and Descending condition

any solution are welcome


Milena
Telerik team
 answered on 13 Sep 2012
5 answers
131 views
Hello,

I'm having a little issue with the RadDock controls.
What I am trying to do is add a WebPart zone in the ContentContainer of my dock. This first step works fine.

EDIT : It works for the raddock which have their states saved in DB and are thus created on the 
dockLayoutHome_LoadDockLayout event.

For the docks that I try to add on "runtime" (I have a RadAjaxPanel which contains the RadDockLayout) I get the following error:
System.ApplicationException: A program is attempting to add a new Web Part Zone to this page. Web Part Zones must be defined at the time a Web Part Page is created.

Any help would be appreciated :)



Then I want to add a WebPart in the previously created WebPartZone. This step also works fine.

The problem is when a postback occurs on the page.
My docks contains the WebPart initially created, and a new one! At every postback, the dock contains a new WebPart...

Here is the code that adds the WebPart:
public class CustomRadDock : RadDock
    {
        #region Overrides
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.EnsureChildControls();
        }
 
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
 
            WebPartZone wpZone = new WebPartZone();
            wpZone.ID = String.Format("{0}_webPartZone", this.ID);
            wpZone.PartChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.TitleOnly;
 
            this.ContentContainer.Controls.Add(wpZone);
            LoadWebPart("myname");
        }
        #endregion Overrides
 
        #region Methods
        private void LoadWebPart(String webPartName_)
        {
            _log.Info("Adding WebPart to dock");
 
            using (SPSite site = new SPSite("mysite"))
            {
                SPWeb web = site.RootWeb;
                SPFile page = web.GetFile("mypage");
 
                web.AllowUnsafeUpdates = true;
                web.Update();
 
                using (SPLimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
                {
                    XmlElement p = new XmlDocument().CreateElement("p");
                    p.InnerText = "Hello World";
                    ContentEditorWebPart cewp = new ContentEditorWebPart();
                    cewp.Content = p;
                    wpmgr.AddWebPart(cewp, String.Format("{0}_webPartZone", this.ID), 0);
                    wpmgr.SaveChanges(cewp);
                }
 
                web.AllowUnsafeUpdates = false;
                web.Update();
            }
        }
        #endregion Methods

Let me know if you need further information.
And if you have any solution of course!
SLM
Top achievements
Rank 1
 answered on 13 Sep 2012
1 answer
36 views

Hi All,
 I am using Radchart(line series) to display the data
I need to display multiple sereis, if one of the series don't contain data for a particluar date,
and if other series has the data for the same date, the point is displaying at the last
as shown in the attached file.

The problem occurring is dates are not displaying in sequence.

Thanks in Advance.
Petar Marchev
Telerik team
 answered on 13 Sep 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?