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();

    for (int i = 0; i < Language.AvailableLanguages().Length; i++)
    if (nRowCount == 0)


    string sImageFileName = "";
    LanguageInfo linfo = Language.AvailableLanguages();
    if (linfo.ID == lng.ID)
    // language is selected
    sImageFileName = "onflag_" + linfo.ShortCode + ".gif";
    // 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);

    if (nRowCount == 3)
    nRowCount = 0;


    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 s., Jun 17, 2005
    1. Advertisements

  2. matthias s.

    Karl Seguin Guest

    Karl Seguin, Jun 17, 2005
    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 s., Jun 17, 2005
  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....


    MY ASP.Net tutorials - New and Improved (yes, the popup is
    annoying) - unofficial newsgroup FAQ (more to
    Karl Seguin, Jun 17, 2005
    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.