5 Replies - 20833 Views - Last Post: 06 October 2007 - 09:15 AM Rate Topic: -----

#1 hyperionza   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 15-September 07

DropDownList's onSelectedIndexChanged going missing?

Posted 05 October 2007 - 11:59 AM

I did find another topic similar to it but... no solution the other topic

My problem is that even though the postback occurs the event handler doesnt run

(if this looks like an earlier query of mine thats coz i gave up using javascript coz it just aint working for me!)

protected void ddl_SMSContact_SelectedIndexChanged(object sender, EventArgs e)
	{
		DropDownList ddl = (DropDownList)sender;
		string t = (string)Session["SMSContacts"];
		if (txt_SMSRecipients.Text.Length != 0)
		{
			t += ", ";
		}
		t += ddl.SelectedValue;
		txt_SMSRecipients.Text = t;
		Session["SMSContacts"] = t;
	}


thats the event handler that doesnt run, ive tested it to death using other event triggers etc seeing if it would fire without autopostback when a button is pressed. Ive also tried to make it reference the DDL directly but no result

the definition of the DDL:
<asp:DropDownList ID="ddl_SMSContact" runat="server"
							Width="184px" onselectedIndexChanged="ddl_SMSContact_SelectedIndexChanged">
						</asp:DropDownList>


just so you can see the event is registered.

There is a case where it does work and thats if ive added in the data staticly in the designer. The data im using comes from a ListItemCollection which is in turn populated from a ... stuff it heres that code to:
string response = (string)Session["SMSContactResponse"];
		SMSContacts = new ListItemCollection();
		if (Session["SMSContactResponse"] == null)
		{
			string message = "<Message><Individual><OwnerGUID>" + ((MasterPg)Master).UserGUID + "</OwnerGUID>" +
				"<Salutation/>" +
				"<Contact_Surname/>" +
				"<Contact_Name/>" +
				"<Cell_Number/>" +
				"</Individual></Message>";
			response = ((MasterPg)Master).getService().Search(message);
			Session["SMSContactResponse"] = response;
			
		}
		SMSContacts.Add(new ListItem("<Quick Search>", ""));
		SMSContacts.AddRange(StaticOperations.getKVPairs(response, new string[] { "Salutation", "Contact_Surname", "Contact_Name" }, new string[] { "Cell_Number" }));
		foreach (ListItem li in SMSContacts)
		{
			ddl_SMSContact.Items.Add(li);
		}


in effect its run off the Page_Load event, fetches the data from a DB (successfully) and populates the DDL. There are a few pointless lines there but i added them in while trying to squash this bug/whatever. though the code still works 100% for what its supposed to do.

I know that during a postback the page is recreated, hence why i tried to use the 'sender' parameter.

I cant think of anything else to say, except if its something stupid on my part please just klap me over the head and then post why, so its over to you now.

Is This A Good Question/Topic? 0
  • +

Replies To: DropDownList's onSelectedIndexChanged going missing?

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: DropDownList's onSelectedIndexChanged going missing?

Posted 05 October 2007 - 12:05 PM

See if this solves your problem (Sorry at work so I dont have the time to create a new project and test it)

protected void ddl_SMSContact_SelectedIndexChanged(object sender, EventArgs e)
	{
		string t = (string)Session["SMSContacts"];
		if (txt_SMSRecipients.Text.Length != 0)
		{
			t += ", ";
		}
		t += this.SelectedValue;
		txt_SMSRecipients.Text = t;
		Session["SMSContacts"] = t;
	}


Was This Post Helpful? 0
  • +
  • -

#3 hyperionza   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 15-September 07

Re: DropDownList's onSelectedIndexChanged going missing?

Posted 05 October 2007 - 04:19 PM

No problem... about the work leastways...

Quote

Compiler Error Message: CS0117: 'Webmail' does not contain a definition for 'SelectedValue'


reason being that 'this' refers to the Page object and not the DDL object that caused the event.

So... Still open to suggestion (and that includes 'Let them do it manually!')

Appreciate the reply Psycho, I think that youve replied to everyone of the questions Ive posted so far! Id buy you a couple of beers or something but unless youre pulling nightshift, youre on the other end of the globe to me.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: DropDownList's onSelectedIndexChanged going missing?

Posted 05 October 2007 - 05:42 PM

I don't know what I was thinking lol, I hadnt had enough coffee this morning :D I just created a DropDownList in a C# Windows Application, then used the SelectedIndexChange Event like this

protected void ddl_SMSContact_SelectedIndexChanged(object sender, EventArgs e)
	{
		string t = (string)Session["SMSContacts"];
		if (txt_SMSRecipients.Text.Length != 0)
		{
			t += ", ";
		}
		t += ddl_SMSContact.SelectedValue;
		txt_SMSRecipients.Text = t;
		Session["SMSContacts"] = t;
	}



And it worked perfectly, so give this a try
Was This Post Helpful? 0
  • +
  • -

#5 hyperionza   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 15-September 07

Re: DropDownList's onSelectedIndexChanged going missing?

Posted 06 October 2007 - 03:46 AM

In theory it should work fine... but thats what I originally tried before I used 'sender'.

Ill try it again though

Update: just got round to it, no luck, still doesnt work. you try it in ASP.NET with C# backing or straight C#?

This post has been edited by hyperionza: 06 October 2007 - 07:59 AM

Was This Post Helpful? 0
  • +
  • -

#6 orcasquall   User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 158
  • Joined: 14-September 07

Re: DropDownList's onSelectedIndexChanged going missing?

Posted 06 October 2007 - 09:15 AM

Have you tried setting the AutoPostBack property to true? Like in
<asp:DropDownList ID="ddl_SMSContact" runat="server"
							Width="184px" onselectedIndexChanged="ddl_SMSContact_SelectedIndexChanged" AutoPostBack="True">
						</asp:DropDownList>



PS. I think I solved the javascript problem in your other post.
Was This Post Helpful? 1

Page 1 of 1