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. Advertising

  2. matthias s.

    Karl Seguin Guest

    use a repeater and bind to it...makes your code cleaner and likely will make
    it work...

    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!)
    "matthias s." <postamt[theat]emvoid[thedot]de> wrote in message
    news:...
    > 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
    >
    >
     
    Karl Seguin, Jun 17, 2005
    #2
    1. Advertising

  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

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    schrieb im Newsbeitrag news:...
    > use a repeater and bind to it...makes your code cleaner and likely will

    make
    > it work...
    >
    > 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!)
    > "matthias s." <postamt[theat]emvoid[thedot]de> wrote in message
    > news:...
    > > 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
    #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!)
    "matthias s." <postamt[theat]emvoid[thedot]de> wrote in message
    news:...
    > Hi Karl,
    >
    > thanks for your answer. Would you mind telling my why it doesn't work
    > anyway? Would be greatly appreciated.
    >
    > /matthias
    >
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > schrieb im Newsbeitrag news:...
    >> use a repeater and bind to it...makes your code cleaner and likely will

    > make
    >> it work...
    >>
    >> 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!)
    >> "matthias s." <postamt[theat]emvoid[thedot]de> wrote in message
    >> news:...
    >> > 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
    >> >
    >> >

    >>
    >>

    >
    >
     
    Karl Seguin, Jun 17, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Yenor
    Replies:
    0
    Views:
    407
    Scott Yenor
    Jan 22, 2004
  2. news.microsoft.com
    Replies:
    1
    Views:
    558
    Teemu Keiski
    Apr 9, 2005
  3. news.microsoft.com

    Custom Templated Control not rendering asp.net controls correctly

    news.microsoft.com, Apr 8, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    173
    Teemu Keiski
    Apr 9, 2005
  4. news.microsoft.com

    Custom Templated Control not rendering asp.net controls correctly

    news.microsoft.com, Apr 8, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    171
    Teemu Keiski
    Apr 9, 2005
Loading...

Share This Page