This is a migrated thread and some comments may be shown as answers.

[Solved] Create Controls in Code

1 Answer 144 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris Rowley
Top achievements
Rank 1
Chris Rowley asked on 22 Apr 2008, 05:54 AM
Howdy,

One of the primary reasons I continue to avoid migrating to .NET from Classic ASP is the focus on visual design in .aspx pages. I develop systems more akin to Content Management Systems where every page is driven by database relationships meaning the visual layout is never predetermined.

While I have owned RadControls for nearly a year and have dabbled with it, there is no standard documentation on how to use the controls solely from code (in my case VB.NET). Is there a chance documentation could be updated or pages added to the support site that have examples of using the controls solely from the code side, where the .aspx is nearly empty?

Also, especially in the case of RadEditor, is there any other way to access the content other than rigid control names? When using JavaScript solutions like TinyMCE I can encode necessary database variables into the ID, but with control names, even using array creates the need for a round-trip to the database to walk the array and align the content with the necessary fields. This situation is another example of why .NET makes Web development more difficult in the .NET world than with Classic ASP. Is there a way to enumerate all of the RadEditors during a postback and walk each one to retrieve its ID?

Chris

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 24 Apr 2008, 11:23 AM
Hi Chris,

The implementation of requested solution is a general knowledge. We are not quite sure what your scenario is but you can try and enhance the code below which could be helpful to get your started:

Default.aspx:
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>

Default.aspx.cs
using System; 
using System.Data; 
using System.Configuration; 
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; 
using Telerik.Web.UI; 
using Telerik.Web.UI.Editor.DialogControls; 
 
 
public partial class _Default : System.Web.UI.Page  
    private int iCnt = 0; 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        AddNewEditor(iCnt); 
        iCnt++; 
    } 
    private void AddNewEditor(int id) 
    { 
        RadEditor editor = new RadEditor(); 
        editor.ID = "Editor" + id; 
        form1.Controls.Add(editor); 
    } 
 
    protected override void LoadViewState(object savedState) 
    { 
        object[] state = (object[])savedState; 
        iCnt = (int)state[0]; 
 
        for (int i = 0; i < iCnt; i++) 
        { 
            AddNewEditor(i); 
        } 
 
        base.LoadViewState(state[1]); 
    } 
 
    protected override object SaveViewState() 
    { 
        object[] state = new object[] { 
            iCnt, 
            base.SaveViewState() 
        }; 
        return state; 
    } 


I hope this helps.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Chris Rowley
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or