1

I have a string stored in DB as "<asp:panel id='test' runat='server' ></asp:panel>". I am trying to get this data and put it in a div which have runat="server" in it using innerHtml property.

protected void Page_Load(object sender, EventArgs e)
{
    Layouts.InnerHtml = GetTemplate();
}

public string GetTemplate()
{
    CompassModel.Layout Layout;
    using (CompassEntities db = new CompassEntities())
    {
        Layout = (from q in db.Layouts
                        where q.LayoutID == 1
                        select q).SingleOrDefault();
    }

    return Layout.LayoutHTML;
}

when I am trying to access this dynamically added panel using findcontrol() method it returns null.

Is there any way to render it so that I can access panel at the runtime?

3
  • 1
    Who gave you the idea to store <asp:panel id='test' runat='server' ></asp:panel> in DB and add it in other control? What are you trying to solve? Commented Oct 15, 2013 at 13:42
  • i have tons of lines in design page. so it is taking to much time to load. Commented Oct 15, 2013 at 13:43
  • Its a worst idea to simply move it to DB. Anyway final output will be rendered as HTML. Howver you are simply putting more load(DB Call) and trying to make your site heavier. Start use Ajax Commented Oct 15, 2013 at 13:50

1 Answer 1

2

You have to look at asp server controls as objects and not markup. The markup is handled by .net once the object is rendered into html.

So just adding the .net markup to the page won't give you the desired effect.

What you need to do is create a new panel object and add that to the control collection of a placeholer, or panel, or any other control that will allow you to add to their collection.

Here's an example of what I'm talking about

pnlContainer.Controls.Add(new Panel{ID = "test"});

Sign up to request clarification or add additional context in comments.

8 Comments

i have lots of different controls and diffrent designs.
What you're trying to do won't work. You either have to add the controls to the collections dynamically, or create sections of the page and show/hide them before the page renders. That will help speed up the load time.
how can you please elaborate the section thing?
Place any "optional" controls in panels. And on init figure out which panels should be shown on the page, and change the visible property on all the panels to reflect the desired layout.
suppose i have 35 panels and i want only 1 panel to show what should i do. these panels are in usercontrol which is being added dynamically to parent page.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.