User Control and Post Back

G

Guest

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

Teemu Keiski

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)
 
G

Guest

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.
 

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,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top