Locating a button BELOW a dynamically-generated control

Posted on 2007-10-18
Last Modified: 2013-11-07
I may have bricked myself into a corner here by saying, "Sure, that's no problem !"

My C# Framework 2.0 app I'm building with VS 2005 reads a policy document on our sister organization's site for display on our own site.  The document originates as a Word doc at the other organization's URL; my page reads it via StreamReader (since my boss said no to iFrames and security policy won't allow us to have Word on the server) into a literal control on my page.  

My boss wants me to move the button to page bottom--for a bit of assurance users have read the policy before signing via button click.  

Trying to relocate the button, I encountered the problem: Having the button at page top--with the dynamically-generated literal control below--is not the same as putting the button below this created-on-the-fly control.  In the latter case, which my boss wants, I see  the button's HTML code if I use View Source--but no button appears in presentation.

I'm a C# newbie.  Is there maybe a late-binding solution or other expedient way to get that button to appear below the policy before we demo for the director ?  Could I put some sort of placeholder on the page that could grow, and locate the button below at design time?

Your counsel appreciated.

From Page Load:

            //the string "sbuild" compiled from the doc goes into the literal control

            frmSignIt.Controls.Add(new System.Web.UI.LiteralControl(sbuild.ToString()));

            //Now that the dynamic-content control is generated, I guess I should put the button after it
            //sequentially in the code (I already tried having it in the .aspx file, but that only works if
            //the button is to appear ABOVE the policy; I need it below)

            string strButton =
                  "<center><asp:Button ID=\"btnSignIt\" runat=\"server\" Text = \"I have read and accept the terms of the Policy\" OnClick = \"btnSignIt_Click\" ></asp:Button> </center>"                
            frmSignIt.Controls.Add(new System.Web.UI.LiteralControl(strButton.ToString()));

Question by:CAWhite
    LVL 96

    Accepted Solution

    You could use the Controls.AddAt(index, control) instead of the Add, and Controls.IndexOf to find the index of the control that you want to add the control after.


    Author Comment

    Never mind.  Yes, there's a placeholder available--the literal control itself.  I had just learned about the control , and hadn't understood I could place a declaration in the aspx rather than adding it dynamically from the codebehind.  


    Author Comment

    Hi Bob,

    Sorry I posted without having seen your comment yet.    That gives me more than one way to do this, thanks !


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now