postback issue

P

Paul

I've written som junk code below to show a problem I'm getting:

On a page I've got a dropdownlist and a button using submit behaviour:

<asp:DropDownList ID="tester" runat="server" AutoPostBack="true"
EnableViewState="False"
OnSelectedIndexChanged="tester_SelectedIndexChanged">
<asp:ListItem Text="All" Value="ALL"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
</asp:DropDownList>

<asp:Button ID="Button1" runat="server" CausesValidation="False"
EnableViewState="False"
OnClick="Button1_Click" Text="Button" />

The codebehind looks like this:

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
tester.SelectedValue =
Request.QueryString["id"].ToString();
}
protected void tester_SelectedIndexChanged(object sender,
EventArgs e)
{
Response.Redirect("test.aspx?id=" +
Request.Form[tester.UniqueID]);
Response.End();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("here");
}
}


Whats happening is that the selectedindexchanged event is causing a
redirect which is passing the value of the selected dropdownlist back
to the page, this is then used to select the listitem relating to the
ID. I know this is convoluted, but it's something I need to use as per
a client request.

My issue is that if the button is pressed before selectedindexchanged,
then the button click event is fired. If the selectedindexchnaged
event fires, then the button click event won't.
From looking at the html, it seems the postback and redirect is
causing the button behaviour to change from submit to text. This stops
the button click event from being fired.
Why is this occuring? And is there anything I can do to stop it from
happening? I've tried programatically changing the buttons submit
behaviour but it doesn't stop this problem from occuring.
 
J

Joe Fawcett

Paul said:
I've written som junk code below to show a problem I'm getting:

On a page I've got a dropdownlist and a button using submit behaviour:

<asp:DropDownList ID="tester" runat="server" AutoPostBack="true"
EnableViewState="False"
OnSelectedIndexChanged="tester_SelectedIndexChanged">
<asp:ListItem Text="All" Value="ALL"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
</asp:DropDownList>

<asp:Button ID="Button1" runat="server" CausesValidation="False"
EnableViewState="False"
OnClick="Button1_Click" Text="Button" />

The codebehind looks like this:

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
tester.SelectedValue =
Request.QueryString["id"].ToString();
}
protected void tester_SelectedIndexChanged(object sender,
EventArgs e)
{
Response.Redirect("test.aspx?id=" +
Request.Form[tester.UniqueID]);
Response.End();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("here");
}
}


Whats happening is that the selectedindexchanged event is causing a
redirect which is passing the value of the selected dropdownlist back
to the page, this is then used to select the listitem relating to the
ID. I know this is convoluted, but it's something I need to use as per
a client request.

My issue is that if the button is pressed before selectedindexchanged,
then the button click event is fired. If the selectedindexchnaged
event fires, then the button click event won't.
From looking at the html, it seems the postback and redirect is
causing the button behaviour to change from submit to text. This stops
the button click event from being fired.
Why is this occuring? And is there anything I can do to stop it from
happening? I've tried programatically changing the buttons submit
behaviour but it doesn't stop this problem from occuring.
Perhaps if you described the requirement rather than the problem/solution it
would be easier to assist?
It sounds quite a convoluted procedure for what seems like a standard task.
 
P

Paul

I've written som junk code below to show a problem I'm getting:
On a page I've got a dropdownlist and a button using submit behaviour:
<asp:DropDownList ID="tester" runat="server" AutoPostBack="true"
EnableViewState="False"
OnSelectedIndexChanged="tester_SelectedIndexChanged">
<asp:ListItem Text="All" Value="ALL"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
</asp:DropDownList>
   <asp:Button ID="Button1" runat="server" CausesValidation="False"
EnableViewState="False"
       OnClick="Button1_Click" Text="Button" />
The codebehind looks like this:
public partial class test : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
       if (Request.QueryString["id"] != null)
           tester.SelectedValue =
Request.QueryString["id"].ToString();
   }
   protected void tester_SelectedIndexChanged(object sender,
EventArgs e)
   {
       Response.Redirect("test.aspx?id=" +
Request.Form[tester.UniqueID]);
       Response.End();
   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       Response.Write("here");
   }
}
Whats happening is that the selectedindexchanged event is causing a
redirect which is passing the value of the selected dropdownlist back
to the page, this is then used to select the listitem relating to the
ID. I know this is convoluted, but it's something I need to use as per
a client request.
My issue is that if the button is pressed before selectedindexchanged,
then the button click event is fired. If the selectedindexchnaged
event fires, then the button click event won't.
From looking at the html, it seems the postback and redirect is
causing the button behaviour to change from submit to text. This stops
the button click event from being fired.
Why is this occuring? And is there anything I can do to stop it from
happening? I've tried programatically changing the buttons submit
behaviour but it doesn't stop this problem from occuring.

Perhaps if you described the requirement rather than the problem/solution it
would be easier to assist?
It sounds quite a convoluted procedure for what seems like a standard task..

The page in question is required to have javascript functionality, but
be perfectly usable for people with JS disabled - making use of the
query string to store search terms and the selected dropdownlist item
- this allows search terms to be saved as a link and pasted in emails
etc.
So a user with JS enabled can select a dropdownlist item and
autopostback will immediately update the search results (the
dropdownlist item will then be placed in the querystring - the reason
for the postback), but if a user doesn't have JS enabled, pressing the
search button (whose submit behaviour gets broken) will update the
query string etc.
Using Response.End() stops the page being re-rendered before the
redirect, which limits performance issues. There is no reason why .net
should change the button submittion behaviour though that I can see.
 

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

Top