Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

postback issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 22 May 2008 01:20 GMT
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.
Joe Fawcett - 22 May 2008 08:50 GMT
> I've written som junk code below to show a problem I'm getting:
>
[quoted text clipped - 52 lines]
> 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.

Signature

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

Paul - 22 May 2008 10:22 GMT
> > I've written som junk code below to show a problem I'm getting:
>
[quoted text clipped - 56 lines]
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.