prerender event

Discussion in 'ASP .Net' started by Yankee Imperialist Dog, Jun 28, 2008.

  1. 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!
     
    Yankee Imperialist Dog, Jun 28, 2008
    #1
    1. Advertising

  2. Yankee Imperialist Dog

    Teemu Keiski Guest

    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" <>
    wrote in message news:D...
    > 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!
     
    Teemu Keiski, Jun 28, 2008
    #2
    1. Advertising

  3. 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" <>
    > wrote in message news:D...
    > > 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!

    >
    >
    >
     
    Yankee Imperialist Dog, Jun 29, 2008
    #3
    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. =?Utf-8?B?QWxpcmV6YSBaaWFp?=

    PreRender Event occurs immediatley after Load event

    =?Utf-8?B?QWxpcmV6YSBaaWFp?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,154
    Hans Kesting
    Feb 9, 2004
  2. DalePres
    Replies:
    1
    Views:
    2,886
    Natty Gur
    May 13, 2004
  3. wardy

    begin prerender event

    wardy, Jun 8, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    534
    wardy
    Jun 8, 2004
  4. wardy
    Replies:
    6
    Views:
    7,221
    John Saunders
    Jun 18, 2004
  5. Jimmy
    Replies:
    5
    Views:
    15,495
    =?Utf-8?B?Sm9yZ2UgTCBNYXRvcyBbTUNTRC5ORVRd?=
    Apr 27, 2005
Loading...

Share This Page