467,184 Members | 1,338 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,184 developers. It's quick & easy.

prerender event

i'm not sure how the preRender event gets handled.

if i have a function:
protected void tbPasswordPreRender(object sender, EventArgs e)
{
tbPswd1.Attributes["value"] = tbPswd1.Text;
tbPswd2.Attributes["value"] = tbPswd2.Text;
}
and set the two text boxes Prerender event to this single function will it
fire twice?
I'm hoping that dot.net is smart enough to do it oncelike the way sqlserver
handles some sub queries.
--
Share The Knowledge. I need all the help I can get and so do you!
Jun 28 '08 #1
  • viewed: 2546
Share:
2 Replies
Hi,

if it is wired to two controls, it will run twice, no question about that -
this has nothing to do with SQL Server's subqueries :-). Controls do not
know about each other unless it is explicitly somehow stated by the page
developer. Controls cannot assume much about logic - like the logic run on
their Prerender event , as the assumption could be wrong, too.

Instead of hardcoding the controls in the event handler, you could rely on
event being raised for specific control and deal with only it.

You could for example run it like this:

//Wiring events somewhere
tbPswd1.PreRender += new EventHandler(tbPasswordPreRender);
tbPswd2.PreRender += new EventHandler(tbPasswordPreRender);
protected void tbPasswordPreRender(object sender, EventArgs e)
{
//Use the knowledge that control raising the event is available via
sender argument
TextBox tb=(TextBox)sender;
tb.Attributes["value"] = tb.Text;
}

When it works equally for all TextBoxes you assign this handler to.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:DA**********************************@microsof t.com...
i'm not sure how the preRender event gets handled.

if i have a function:
protected void tbPasswordPreRender(object sender, EventArgs e)
{
tbPswd1.Attributes["value"] = tbPswd1.Text;
tbPswd2.Attributes["value"] = tbPswd2.Text;
}
and set the two text boxes Prerender event to this single function will it
fire twice?
I'm hoping that dot.net is smart enough to do it oncelike the way
sqlserver
handles some sub queries.
--
Share The Knowledge. I need all the help I can get and so do you!

Jun 28 '08 #2
thank you for replying,
where in the page cycle should i drop this so that it will call once?

--
Share The Knowledge. I need all the help I can get and so do you!
"Teemu Keiski" wrote:
Hi,

if it is wired to two controls, it will run twice, no question about that -
this has nothing to do with SQL Server's subqueries :-). Controls do not
know about each other unless it is explicitly somehow stated by the page
developer. Controls cannot assume much about logic - like the logic run on
their Prerender event , as the assumption could be wrong, too.

Instead of hardcoding the controls in the event handler, you could rely on
event being raised for specific control and deal with only it.

You could for example run it like this:

//Wiring events somewhere
tbPswd1.PreRender += new EventHandler(tbPasswordPreRender);
tbPswd2.PreRender += new EventHandler(tbPasswordPreRender);
protected void tbPasswordPreRender(object sender, EventArgs e)
{
//Use the knowledge that control raising the event is available via
sender argument
TextBox tb=(TextBox)sender;
tb.Attributes["value"] = tb.Text;
}

When it works equally for all TextBoxes you assign this handler to.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Yankee Imperialist Dog" <Ya******************@discussions.microsoft.com>
wrote in message news:DA**********************************@microsof t.com...
i'm not sure how the preRender event gets handled.

if i have a function:
protected void tbPasswordPreRender(object sender, EventArgs e)
{
tbPswd1.Attributes["value"] = tbPswd1.Text;
tbPswd2.Attributes["value"] = tbPswd2.Text;
}
and set the two text boxes Prerender event to this single function will it
fire twice?
I'm hoping that dot.net is smart enough to do it oncelike the way
sqlserver
handles some sub queries.
--
Share The Knowledge. I need all the help I can get and so do you!


Jun 29 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Alireza Ziai | last post: by
reply views Thread by wardy | last post: by
7 posts views Thread by wardy | last post: by
3 posts views Thread by Matt Jensen | last post: by
1 post views Thread by John Dalberg | last post: by
2 posts views Thread by Joe | last post: by
2 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.