custom controls / dynamic control rendering question

Discussion in 'ASP .Net' started by matthias s., Jun 17, 2005.

  1. matthias s.

    matthias s. Guest

    Hi there,

    I'm building a usercontrol to provide language selection options. The
    availabe languages are retrieved dynamically and should be shown as flags
    (ImageButtons) in a table.

    But I've got a problem with formatting the whole thing. I'm using
    Response.Write statements to write the table. Here is a code snippet (the
    fat logic is omitted and I hope the variable names are selfexplanatory):

    +++
    Language lng = new Language();
    Response.Write("<table>");

    for (int i = 0; i < Language.AvailableLanguages().Length; i++)
    {
    if (nRowCount == 0)
    Response.Write("<tr>");

    Response.Write("<td>");

    string sImageFileName = "";
    LanguageInfo linfo = Language.AvailableLanguages();
    if (linfo.ID == lng.ID)
    {
    // language is selected
    sImageFileName = "onflag_" + linfo.ShortCode + ".gif";
    }
    else
    {
    // not selected
    sImageFileName = "offflag_" + linfo.ShortCode + ".gif";
    }

    // create an imagebutton control and set the properties
    ImageButton btn = new ImageButton();
    btn.ID = linfo.ShortCode;
    btn.ImageUrl = "~/Lib/Images/" + sImageFileName;
    btn.Click += new System.Web.UI.ImageClickEventHandler(btn_Click);
    Controls.Add(btn);
    Response.Write("</td>");

    if (nRowCount == 3)
    {
    Response.Write("</tr>");
    nRowCount = 0;
    }
    else
    nRowCount++;
    }

    Response.Write("</table>");
    +++

    In the source of the resulting html page, I can't find any of the html I've
    written with response write. The images are there, but none of the html.

    How do I do this properly?

    P.S.: If it matters, the LanguageSelectionControl (in who's Page_Load event
    the above code is placed) is itself nested in a HeaderControl (as well my
    own make).

    Any hints are greatly appreciated!

    /matthias
     
    matthias s., Jun 17, 2005
    #1
    1. Advertisements

  2. matthias s.

    Karl Seguin Guest

    Karl Seguin, Jun 17, 2005
    #2
    1. Advertisements

  3. matthias s.

    matthias s. Guest

    Hi Karl,

    thanks for your answer. Would you mind telling my why it doesn't work
    anyway? Would be greatly appreciated.

    /matthias

     
    matthias s., Jun 17, 2005
    #3
  4. matthias s.

    Karl Seguin Guest

    My guess is that it does work, just not like you expect.

    The table is likely getting rendered atop your page, before the <html> or at
    the bottom after your </html>. Response.Write doesn't inject the code in
    "the right place"...because how can it know what the 'right place' is....


    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
     
    Karl Seguin, Jun 17, 2005
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.