User Control and Post Back

Discussion in 'ASP .Net' started by =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?=, Jul 1, 2006.

  1. Hello,
    I have written a user control and I want to execute some part of code only
    when the page that contains the user control is on a "postback". I would like
    that part of the code to be in the 'User control" class itself than to write
    the code on every page of my application that contains the user control.

    Can someone help me how I would handle this?

    Thanks.
    =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?=, Jul 1, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?=

    Teemu Keiski Guest

    Hi,

    user control can simply check

    'VB
    If Me.Page.IsPostBack Then
    'Do something...
    End If

    //C#
    if(this.Page.IsPostBack){
    //Do something
    }

    E.g this code can exist in UC. (And in fact., it has Page property so you
    don't even need Me or this in it, e.g syntax is exactly the same as doing it
    on Page)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    "Ganesh Muthuvelu" <> wrote in
    message news:...
    > Hello,
    > I have written a user control and I want to execute some part of code only
    > when the page that contains the user control is on a "postback". I would
    > like
    > that part of the code to be in the 'User control" class itself than to
    > write
    > the code on every page of my application that contains the user control.
    >
    > Can someone help me how I would handle this?
    >
    > Thanks.
    Teemu Keiski, Jul 1, 2006
    #2
    1. Advertising

  3. Hi,
    Thanks for your reply. But where should I call this in the user control?.
    PreRender event?.
    I get the Me.Page as "Nothing" all times.. Please help.

    Thanks.

    "Teemu Keiski" wrote:

    > Hi,
    >
    > user control can simply check
    >
    > 'VB
    > If Me.Page.IsPostBack Then
    > 'Do something...
    > End If
    >
    > //C#
    > if(this.Page.IsPostBack){
    > //Do something
    > }
    >
    > E.g this code can exist in UC. (And in fact., it has Page property so you
    > don't even need Me or this in it, e.g syntax is exactly the same as doing it
    > on Page)
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    >
    > "Ganesh Muthuvelu" <> wrote in
    > message news:...
    > > Hello,
    > > I have written a user control and I want to execute some part of code only
    > > when the page that contains the user control is on a "postback". I would
    > > like
    > > that part of the code to be in the 'User control" class itself than to
    > > write
    > > the code on every page of my application that contains the user control.
    > >
    > > Can someone help me how I would handle this?
    > >
    > > Thanks.

    >
    >
    >
    =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?=, Jul 1, 2006
    #3
  4. Doesn't your userControl have a Page_Load handler? Try doing your check
    there. If you don't have access to the Page (the parent page) property at
    that point, then you have the unfortunate luxury of a completely different
    type of problem.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Ganesh Muthuvelu" wrote:

    > Hi,
    > Thanks for your reply. But where should I call this in the user control?.
    > PreRender event?.
    > I get the Me.Page as "Nothing" all times.. Please help.
    >
    > Thanks.
    >
    > "Teemu Keiski" wrote:
    >
    > > Hi,
    > >
    > > user control can simply check
    > >
    > > 'VB
    > > If Me.Page.IsPostBack Then
    > > 'Do something...
    > > End If
    > >
    > > //C#
    > > if(this.Page.IsPostBack){
    > > //Do something
    > > }
    > >
    > > E.g this code can exist in UC. (And in fact., it has Page property so you
    > > don't even need Me or this in it, e.g syntax is exactly the same as doing it
    > > on Page)
    > >
    > > --
    > > Teemu Keiski
    > > ASP.NET MVP, AspInsider
    > > Finland, EU
    > > http://blogs.aspadvice.com/joteke
    > >
    > >
    > > "Ganesh Muthuvelu" <> wrote in
    > > message news:...
    > > > Hello,
    > > > I have written a user control and I want to execute some part of code only
    > > > when the page that contains the user control is on a "postback". I would
    > > > like
    > > > that part of the code to be in the 'User control" class itself than to
    > > > write
    > > > the code on every page of my application that contains the user control.
    > > >
    > > > Can someone help me how I would handle this?
    > > >
    > > > Thanks.

    > >
    > >
    > >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jul 2, 2006
    #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. sk2000
    Replies:
    2
    Views:
    4,411
    Kumar
    Nov 12, 2003
  2. =?Utf-8?B?VHJveQ==?=

    user control dissapears from panel on post back

    =?Utf-8?B?VHJveQ==?=, Jan 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    477
    Marina
    Jan 23, 2004
  3. Joby
    Replies:
    0
    Views:
    1,612
  4. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    749
    Masudur
    May 25, 2007
  5. James Todman

    Problem with Post Back and User Control

    James Todman, Oct 12, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    143
    James Todman
    Oct 12, 2004
Loading...

Share This Page