Calendar rendering

T

Trond

I'm having a problem when creating several calendars in a web form.
Here's a snippet of my code:

******************************
public string username;

private void CreateCalendars()
{
....misc DB-stuff

while (dr.Read())
{
username = dr["username"].ToString; //Sets the current user's
username
//to the global
variable,username.

Calendar usercalendar = new Calendar();
usercalendar.ID = "cal" + username ;
usercalendar.DayRender += new DayRenderEventHandle

(this.Calendar_dayrender);
usercalendar.SelectionChanged += new EventHandle

(this.Calendar_selectday);

PlaceHolder1.Controls.Add(usercalendar);
}
}

private void Calendar_dayrender(object sender, DayRenderEventArgs e)
{
Response.Write(username); //Should be written for every
while- //loops, not after the
last one.
}
**************************
My problem is:
The dayrender method writes the LAST user's username for every
calendars.
That means, the placeholder does not render the calendar object for
every while-loop.

Are there any work-arounds here?

Thanks in advance!
 
B

Ben Lucas

By doing a Response.Write, you are writing directly to the page. You should
instead modify the controls that are making up each of the Day cells so that
they display what you want. For example:

private void Calendar_dayrender(object sender, DayRenderEventArgs e)
{
Calendar cal = (Calendar)sender;
string sUserName = cal.ID.Remove(0,3); //remove the "cal" from the ID to
get user name
e.Cell.Controls.Add(new LiteralControl(sUserName));
}

Using the global variable is what is throwing you off also. The event does
not get triggered until after you've made it through the entire while loop.
This means that by the time the DayRender event gets called for any of the
calendars, what is in the global variable is the last username.
 
T

Trond

Thank you very much Ben! You saved my weekend :)


Ben Lucas said:
By doing a Response.Write, you are writing directly to the page. You should
instead modify the controls that are making up each of the Day cells so that
they display what you want. For example:

private void Calendar_dayrender(object sender, DayRenderEventArgs e)
{
Calendar cal = (Calendar)sender;
string sUserName = cal.ID.Remove(0,3); //remove the "cal" from the ID to
get user name
e.Cell.Controls.Add(new LiteralControl(sUserName));
}

Using the global variable is what is throwing you off also. The event does
not get triggered until after you've made it through the entire while loop.
This means that by the time the DayRender event gets called for any of the
calendars, what is in the global variable is the last username.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

Trond said:
I'm having a problem when creating several calendars in a web form.
Here's a snippet of my code:

******************************
public string username;

private void CreateCalendars()
{
...misc DB-stuff

while (dr.Read())
{
username = dr["username"].ToString; //Sets the current user's
username
//to the global
variable,username.

Calendar usercalendar = new Calendar();
usercalendar.ID = "cal" + username ;
usercalendar.DayRender += new DayRenderEventHandle

(this.Calendar_dayrender);
usercalendar.SelectionChanged += new EventHandle

(this.Calendar_selectday);

PlaceHolder1.Controls.Add(usercalendar);
}
}

private void Calendar_dayrender(object sender, DayRenderEventArgs e)
{
Response.Write(username); //Should be written for every
while- //loops, not after the
last one.
}
**************************
My problem is:
The dayrender method writes the LAST user's username for every
calendars.
That means, the placeholder does not render the calendar object for
every while-loop.

Are there any work-arounds here?

Thanks in advance!
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top