Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdown list event issue

Status
Not open for further replies.

clyde11

Programmer
Feb 6, 2006
25
GB
Hello all,

I’m using this DropdownList’s webcpntrol, in an asp.net web application (C#)

While making the AutoPostBack = “True”,
When choosing a dropdown list item (let’s say in page1.aspx) the relevant handler is invoked and redirecting to diff. page
when returning back to the 1st page (page1.aspx) and firing a diff. event (i.e. clicking some button that invokes some handler) the same
Handler for the dropdown list is invoked…

Can’t figute it out, any explanation will be appreciated !

Thanks in advance,
P.



 
try this in your ASPX file:

<body ... onload="document.forms[0].__EVENTTARGET.value=''">

does that work???

Known is handfull, Unknown is worldfull
 
Hi thanks,



put the <body .. onload="document.forms[0].__EVENTTARGET.value=''">

in the .aspx html source and it's not

working...(same thing happens, as described in the 1st post)

Thanks,
P.
 
hi,

try a different control other than a button (like some other dropdown that has a postback).

is the same happening???

Known is handfull, Unknown is worldfull
 
Yes, the same happens,

I’m choosing from a dropdown list,
The "SelectedIndexChanged" handler simply do a Response.redirect() to other page, and from that page I’m clicking the "Back" IE button,

When going back to the 1st page, the drop down list's selected item is the last one used (the last selected one)

Then, every event that happens (any button clicking or different dropdownlists clicking) will trigger this dropdown list "SelectedIndexChanged" event, although the dropdown list itself haven't been clicked...

Thanks,
P.

 
can i have some sample coding? just a simple page with 2 dropdowns and one submit button?

what you say is very strange, need to check the sample code...

Known is handfull, Unknown is worldfull
 
Sure,
(but in my app. i don't use a submit button, i'm using the
AutoPostBack to fire the event when selection changed)

Code:
======


<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication_to_delete_this_Proj.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 152px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="0">0</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 102; LEFT: 240px; POSITION: absolute; TOP: 152px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
</asp:DropDownList>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 136px; POSITION: absolute; TOP: 96px" runat="server"
Text="call empty handler"></asp:Button>
</form>
</body>
</HTML>



when the C# WebForm1.aspx.cs is:
================================
================================


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication_to_delete_this_Proj
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{

}

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}

private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
Response.Redirect("WebForm3.aspx");
}
}
}





* while WebForm2 and WebForm3 are just empty pages
* to see which event triggers

so, when WebForm1 loads, i'm changing selection in dropdownlist1 which causes the handler to call response.Redirect("WebForm2.aspx"),

then, clicking back in the IE window, and selecting some item from dropdownlist2 (or pressing the button),

DropDownlist1 handler is invoked (and not the item I clicked...)


Thanks,
P.
 
hi,

this looks like an intrinsic problem in ASP.NET.

i am also getting the same results. will let you know if i make a break through in this...

Known is handfull, Unknown is worldfull
 
I'm seeing the same problem. My analysis says this:

Most button type events will trigger the event code before the postback and subsequent page load. DropDownLists will do just the opposite - repost the page and trigger the event associated with the control.

This seems to be tru for other non-button controls. But, of course, the DropDownList is the control that most of us want to act as a selector. ('cause we're used to using it in JScript).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top