IsPostBack......possible?

Discussion in 'ASP .Net' started by =?Utf-8?B?VEo=?=, Oct 17, 2004.

  1. Hi,

    There is one aspx web page that contains usercontrol.
    In aspx page and usercontrol , there is each submit button...

    Here is what I want...

    I want to process something depending on each page's IsPostBack property...
    For exmple....
    when I click the submit button which is in usercontrol, ASPX page should
    not be affected by the action. Also when I clck the submit button which is in
    aspx page, usercontrol should not be affected by the action (In other words,
    IsPostBack property (which is in usercontrol) should not be set as true...)

    Is this possible?...

    If not, how can I work around?

    Any suggession would be appreciated.

    Thanks.
    =?Utf-8?B?VEo=?=, Oct 17, 2004
    #1
    1. Advertising

  2. You should be responding to each buttons click event. If you have code
    that is running on postback regardless of what event caused it, you will
    need to redesign.

    Typically, in the page load (page or usercontrol), you only check if it's
    not a postback and do some initialization functions like load data. Then
    everything else is handled through the webcontrol's event handlers.

    You can only click one button at a time, so you can be assured that
    either the page or the usercontrol will respond properly to its own click
    event. The page and usercontrol should not do any extra logic in the
    page load.

    There are always exceptions and if your scenario is one, let me know so I
    can clarify my answer.


    "=?Utf-8?B?VEo=?=" <> wrote in
    news:D:

    > Hi,
    >
    > There is one aspx web page that contains usercontrol.
    > In aspx page and usercontrol , there is each submit button...
    >
    > Here is what I want...
    >
    > I want to process something depending on each page's IsPostBack
    > property... For exmple....
    > when I click the submit button which is in usercontrol, ASPX page
    > should not be affected by the action. Also when I clck the submit
    > button which is in aspx page, usercontrol should not be affected by
    > the action (In other words, IsPostBack property (which is in
    > usercontrol) should not be set as true...)
    >
    > Is this possible?...
    >
    > If not, how can I work around?
    >
    > Any suggession would be appreciated.
    >
    > Thanks.
    >
    >
    >
    cbDevelopment, Oct 17, 2004
    #2
    1. Advertising

  3. First of all, thanks for your responding..


    "cbDevelopment" wrote:

    > You should be responding to each buttons click event. If you have code
    > that is running on postback regardless of what event caused it, you will
    > need to redesign.
    >
    > Typically, in the page load (page or usercontrol), you only check if it's
    > not a postback and do some initialization functions like load data. Then
    > everything else is handled through the webcontrol's event handlers.
    >
    > You can only click one button at a time, so you can be assured that
    > either the page or the usercontrol will respond properly to its own click
    > event. The page and usercontrol should not do any extra logic in the
    > page load.


    => Yes , that's correct only one button is clicked at a time. What I was
    asking...
    Here is some snippet code...

    This is Page_Load event in UserControl

    .....Page_Load(...) {
    if(this.IsPostBack) {
    do something 'A' when IsPostBack is true
    }
    else
    {
    do something 'B' when IsPostBack is false
    }
    }


    This is Page_Load event in Aspx page(As I said, above usercontrol is embeded
    in this aspx page)

    .....Page_Load(...) {
    if(this.IsPostBack) {
    do something 'C' when IsPostBack is true
    }
    else
    {
    do something 'D' when IsPostBack is false
    }
    }


    In Aspx page, when I click the submit button, IsPostBack is going to be
    true, do something 'C' will be exectued, and also do something 'A' will be
    executed since IsPostBack is true...It makes sense, but that's not what I
    wanted. I don't want to execute do something 'A' part since postback value
    was set by aspx page..
    Would it be possible scenario?...
    If it's not, is there any functionality that I can get some information
    where the ispostback was set like from aspx page or usercontrol something
    like that?
    ...or any other design I can approach better?

    Thanks again.


    > There are always exceptions and if your scenario is one, let me know so I
    > can clarify my answer.
    >
    >
    > "=?Utf-8?B?VEo=?=" <> wrote in
    > news:D:
    >
    > > Hi,
    > >
    > > There is one aspx web page that contains usercontrol.
    > > In aspx page and usercontrol , there is each submit button...
    > >
    > > Here is what I want...
    > >
    > > I want to process something depending on each page's IsPostBack
    > > property... For exmple....
    > > when I click the submit button which is in usercontrol, ASPX page
    > > should not be affected by the action. Also when I clck the submit
    > > button which is in aspx page, usercontrol should not be affected by
    > > the action (In other words, IsPostBack property (which is in
    > > usercontrol) should not be set as true...)
    > >
    > > Is this possible?...
    > >
    > > If not, how can I work around?
    > >
    > > Any suggession would be appreciated.
    > >
    > > Thanks.
    > >
    > >
    > >

    >
    >
    =?Utf-8?B?VEo=?=, Oct 17, 2004
    #3
  4. This is how I would expect it happen: (sorry, I'm VB and you're C#)

    IN ASPX PAGE
    sub Page_load(s,e)
    if not isPostback then
    ' Perform Task B (This only happens once when the page first loads)
    ' B and D will run together because it is the first load for each
    end if
    end sub

    sub Btn_Click(s,e)
    ' Perform Task A
    ' Note that B, C, and D do not run.
    ' no B because it is a postback
    ' no C because that's not the button that was clicked
    ' no D because it's a postback
    end sub

    IN USERCONTROL
    sub Page_load(s,e)
    if not isPostback then
    ' Perform Task D (This only happens once when the
    ' control first loads. The page's Load event happens
    ' first, then the user control's Load)
    ' So on initial load, Task B and D run together
    ' No buttons are clicked so A and C don't run
    end if
    end sub

    sub Btn_Click(s,e)
    ' Perform Task C
    ' This follows the same logic as the Page's button.
    ' It is a postback so B and D don't run
    ' A doesn't run because it's not the button that was clicked
    end sub

    "=?Utf-8?B?VEo=?=" <> wrote in
    news::

    > First of all, thanks for your responding..
    >
    >
    > "cbDevelopment" wrote:
    >
    >> You should be responding to each buttons click event. If you have
    >> code that is running on postback regardless of what event caused it,
    >> you will need to redesign.
    >>
    >> Typically, in the page load (page or usercontrol), you only check if
    >> it's not a postback and do some initialization functions like load
    >> data. Then everything else is handled through the webcontrol's event
    >> handlers.
    >>
    >> You can only click one button at a time, so you can be assured that
    >> either the page or the usercontrol will respond properly to its own
    >> click event. The page and usercontrol should not do any extra logic
    >> in the page load.

    >
    > => Yes , that's correct only one button is clicked at a time. What I
    > was
    > asking...
    > Here is some snippet code...
    >
    > This is Page_Load event in UserControl
    >
    > ....Page_Load(...) {
    > if(this.IsPostBack) {
    > do something 'A' when IsPostBack is true
    > }
    > else
    > {
    > do something 'B' when IsPostBack is false
    > }
    > }
    >
    >
    > This is Page_Load event in Aspx page(As I said, above usercontrol is
    > embeded in this aspx page)
    >
    > ....Page_Load(...) {
    > if(this.IsPostBack) {
    > do something 'C' when IsPostBack is true
    > }
    > else
    > {
    > do something 'D' when IsPostBack is false
    > }
    > }
    >
    >
    > In Aspx page, when I click the submit button, IsPostBack is going to
    > be true, do something 'C' will be exectued, and also do something 'A'
    > will be executed since IsPostBack is true...It makes sense, but that's
    > not what I wanted. I don't want to execute do something 'A' part since
    > postback value was set by aspx page..
    > Would it be possible scenario?...
    > If it's not, is there any functionality that I can get some
    > information where the ispostback was set like from aspx page or
    > usercontrol something like that?
    > ..or any other design I can approach better?
    >
    > Thanks again.
    >
    >
    >> There are always exceptions and if your scenario is one, let me know
    >> so I can clarify my answer.
    >>
    >>
    >> "=?Utf-8?B?VEo=?=" <> wrote in
    >> news:D:
    >>
    >> > Hi,
    >> >
    >> > There is one aspx web page that contains usercontrol.
    >> > In aspx page and usercontrol , there is each submit button...
    >> >
    >> > Here is what I want...
    >> >
    >> > I want to process something depending on each page's IsPostBack
    >> > property... For exmple....
    >> > when I click the submit button which is in usercontrol, ASPX page
    >> > should not be affected by the action. Also when I clck the submit
    >> > button which is in aspx page, usercontrol should not be affected by
    >> > the action (In other words, IsPostBack property (which is in
    >> > usercontrol) should not be set as true...)
    >> >
    >> > Is this possible?...
    >> >
    >> > If not, how can I work around?
    >> >
    >> > Any suggession would be appreciated.
    >> >
    >> > Thanks.
    >> >
    >> >
    >> >

    >>
    >>

    >
    cbDevelopment, Oct 17, 2004
    #4
  5. Thanks again, but I wasn't asking how the IsPostBack works....
    Well...basically..what I was asking in short...

    First of all....

    Both ASPX and Usercontrol page have both processing code when IsPostback is
    true and false becuase I need to process something depending on each possible
    event...

    When IsPostBack was set as true because submit button was clicked in aspx
    page, the part of code(when IsPostBack is true in UserControl ) should not be
    executed.
    Each code in Page_Load should only be executed accordingly where the
    ispostback was set from such as aspx page or usercontrol...
    You know what I am saying?

    I guess, in general design, that would be impossible, however, I guess there
    must be some work around way....

    Thanks again.



    "cbDevelopment" wrote:

    > This is how I would expect it happen: (sorry, I'm VB and you're C#)
    >
    > IN ASPX PAGE
    > sub Page_load(s,e)
    > if not isPostback then
    > ' Perform Task B (This only happens once when the page first loads)
    > ' B and D will run together because it is the first load for each
    > end if
    > end sub
    >
    > sub Btn_Click(s,e)
    > ' Perform Task A
    > ' Note that B, C, and D do not run.
    > ' no B because it is a postback
    > ' no C because that's not the button that was clicked
    > ' no D because it's a postback
    > end sub
    >
    > IN USERCONTROL
    > sub Page_load(s,e)
    > if not isPostback then
    > ' Perform Task D (This only happens once when the
    > ' control first loads. The page's Load event happens
    > ' first, then the user control's Load)
    > ' So on initial load, Task B and D run together
    > ' No buttons are clicked so A and C don't run
    > end if
    > end sub
    >
    > sub Btn_Click(s,e)
    > ' Perform Task C
    > ' This follows the same logic as the Page's button.
    > ' It is a postback so B and D don't run
    > ' A doesn't run because it's not the button that was clicked
    > end sub
    >
    > "=?Utf-8?B?VEo=?=" <> wrote in
    > news::
    >
    > > First of all, thanks for your responding..
    > >
    > >
    > > "cbDevelopment" wrote:
    > >
    > >> You should be responding to each buttons click event. If you have
    > >> code that is running on postback regardless of what event caused it,
    > >> you will need to redesign.
    > >>
    > >> Typically, in the page load (page or usercontrol), you only check if
    > >> it's not a postback and do some initialization functions like load
    > >> data. Then everything else is handled through the webcontrol's event
    > >> handlers.
    > >>
    > >> You can only click one button at a time, so you can be assured that
    > >> either the page or the usercontrol will respond properly to its own
    > >> click event. The page and usercontrol should not do any extra logic
    > >> in the page load.

    > >
    > > => Yes , that's correct only one button is clicked at a time. What I
    > > was
    > > asking...
    > > Here is some snippet code...
    > >
    > > This is Page_Load event in UserControl
    > >
    > > ....Page_Load(...) {
    > > if(this.IsPostBack) {
    > > do something 'A' when IsPostBack is true
    > > }
    > > else
    > > {
    > > do something 'B' when IsPostBack is false
    > > }
    > > }
    > >
    > >
    > > This is Page_Load event in Aspx page(As I said, above usercontrol is
    > > embeded in this aspx page)
    > >
    > > ....Page_Load(...) {
    > > if(this.IsPostBack) {
    > > do something 'C' when IsPostBack is true
    > > }
    > > else
    > > {
    > > do something 'D' when IsPostBack is false
    > > }
    > > }
    > >
    > >
    > > In Aspx page, when I click the submit button, IsPostBack is going to
    > > be true, do something 'C' will be exectued, and also do something 'A'
    > > will be executed since IsPostBack is true...It makes sense, but that's
    > > not what I wanted. I don't want to execute do something 'A' part since
    > > postback value was set by aspx page..
    > > Would it be possible scenario?...
    > > If it's not, is there any functionality that I can get some
    > > information where the ispostback was set like from aspx page or
    > > usercontrol something like that?
    > > ..or any other design I can approach better?
    > >
    > > Thanks again.
    > >
    > >
    > >> There are always exceptions and if your scenario is one, let me know
    > >> so I can clarify my answer.
    > >>
    > >>
    > >> "=?Utf-8?B?VEo=?=" <> wrote in
    > >> news:D:
    > >>
    > >> > Hi,
    > >> >
    > >> > There is one aspx web page that contains usercontrol.
    > >> > In aspx page and usercontrol , there is each submit button...
    > >> >
    > >> > Here is what I want...
    > >> >
    > >> > I want to process something depending on each page's IsPostBack
    > >> > property... For exmple....
    > >> > when I click the submit button which is in usercontrol, ASPX page
    > >> > should not be affected by the action. Also when I clck the submit
    > >> > button which is in aspx page, usercontrol should not be affected by
    > >> > the action (In other words, IsPostBack property (which is in
    > >> > usercontrol) should not be set as true...)
    > >> >
    > >> > Is this possible?...
    > >> >
    > >> > If not, how can I work around?
    > >> >
    > >> > Any suggession would be appreciated.
    > >> >
    > >> > Thanks.
    > >> >
    > >> >
    > >> >
    > >>
    > >>

    > >

    >
    >
    =?Utf-8?B?VEo=?=, Oct 17, 2004
    #5
    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. Nathan Baulch
    Replies:
    1
    Views:
    967
    Nathan Baulch
    Jun 26, 2003
  2. suzy
    Replies:
    11
    Views:
    750
    Rajeev Soni
    Aug 6, 2003
  3. Matthew
    Replies:
    1
    Views:
    1,476
    Matthew
    Nov 12, 2003
  4. Boris Zakharin

    IsPostBack returns false

    Boris Zakharin, Nov 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    643
    Boris Zakharin
    Nov 19, 2003
  5. Joey
    Replies:
    2
    Views:
    3,939
Loading...

Share This Page