IsPostBack......possible?

G

Guest

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

cbDevelopment

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

Guest

First of all, thanks for your responding..


cbDevelopment said:
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.
 
C

cbDevelopment

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
 
G

Guest

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.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top