I have this problem, pls help!

P

Paul Fi

I have this page Index.aspx, page code shown below:

void Page_Load(object sender, EventArgs e) {

if (IsPostBack) {
if (this.drpTypeOfStock.SelectedIndex != 0)
Server.Transfer("SearchStockType.aspx");
}

//Connection Configuration
ConnToDB();
drpTypeOfStock.DataSource=CreateDataSource();
}

public string StockType {
get{
return this.drpTypeOfStock.SelectedItem.Text;
}
}

private ICollection CreateDataSource() {
ArrayList Types = new ArrayList();
Types.Add("");
while (this.sqlDataReader1.Read()) {
Types.Add(this.sqlDataReader1.GetString(0));
}
return Types;
}

void btnRecentAcquisitions_Click(object sender, EventArgs e) {
Response.Redirect("SearchRecentAcquisitions.aspx");
}

void btnAntiques_Click(object sender, EventArgs e){

Response.Redirect("SearchAntiques.aspx");
}

void drpTypeOfStock_SelectedIndexChanged(object sender, EventArgs e) {

}

Ok here is the scenario, Index.aspx has dropdownlist (its autopostback
is set to true) and 2 button and when Index.aspx is first loaded the
dropdown is populated with entries from a column of sql database table,
now if i choose from that list, I postback and transfered to
SearchStockType.aspx to display results of my selection, now i want to
go back to page1 by clicking on the Back button of the browser then I
click on any of the two buttons to go to another page, say
SearchAntiques.aspx, I end up going back to SearchStockType.aspx which
is the same page that i displayed earlier when i made that selection of
the drop down list, can some one tell me how i can solve this problem?
 
W

WJ

Paul Fi said:
I have this page Index.aspx, page code shown below:

void Page_Load(object sender, EventArgs e) {

if (IsPostBack) {
if (this.drpTypeOfStock.SelectedIndex != 0)
Server.Transfer("SearchStockType.aspx");
}

Because "btnAntiques" and "btnRecentAcquisitions" are server controls,
therefore, whenever you click at any of them, the "this.IsPostBack" is
always TRUE, and based on your code above, you tell it to go straight to
page "SearchStockType.aspx". To avoid this problem, you should implement the
"drpTypeOfStock_SelectedIndexChanged" event handler instead, as listed
below:

private void drpTypeOfStock_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Server.Transfer("SearchStockType.aspx");
}

and your on Page_Load should be:

void Page_Load(object sender, EventArgs e)
{

if (!this.IsPostBack)
{
//Connection Configuration
ConnToDB();
drpTypeOfStock.DataSource=CreateDataSource();
}

}

John
 
P

Paul Fi

ok i just tried that before you replied to me and still getting the same
problem here, i just dont get it!
 
W

WJ

Paul,

It works for me. I have no problem with my code. Did you ever edit the HTML
codes on any of the forms ? If you did, try to resync the code behind with
the design surfaces, recompile and run the program.

John
 
P

Paul Fi

Im using inline code, im not using code-behind, but do you have a
complete code of a page like mine where it works? something that you
worked with or done yourself that is similar to my page, may be that
will help?

thank you
 
W

WJ

Paul,

Today I was abale to re-create your problem. Yes I am now facing the same
thing as you are. I doing so, I also created a new BUG: When I select the
very 1st item from the DDL, it does not post back. At this time then I can
click on other event button. I think the IE/Back button is the one that
screws up our paths. I am interested in solving problem.

Note: I will post the entire sample problem today when I get home from
church in hoping to get attention from MS folks to give us some solutions.

BTW: I am using .NFW 1.1, Windows XP Pro. Service Pack 2. Though I did
reinstalled IIS-5 on my XP after Sp2 applied and have not reapplied XP/sp2.
I will test on my laptop to see if I can re-create the same problem.

This is a serious BUG! Thanks for bringing it up because I have applications
like that too.

I will be back.

John
 
W

WJ

I have created a new follow up post under "Bugs found in Asp.Net application
(SERIOUS)". Yes, I did finally recreate the problem your are facing.

John
 
P

Paul Fi

Hi John,

Im not sure why your dropdownlist doesnt work for the first item like
youre saying but that is not exactly what im getting, in here I have the
page that when i made a selection from the dropdownlist, a transfer to
another page is made, then i decide to go back to Index.aspx, which has
that dropdownlist and other controls like buttons now i click on one of
those buttons what i get is that same page that i was transferred to
earlier but that is not what i want when i make that button click coz
that page transfer should only be done when i made a selection change
from the dropdownlist. I think it seems to think that there is a
selection change made to the dropdownlist everytime there is a postback
to Index.aspx even if i do button clicks. It seems to be somekind of a
bug or a design problem or something coz that shouldnt happen i think
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top