Hi I ran some test code and it doesn't seem to be the casing. It seems like some thing's just not working with dynamically modifying attributes of a drop down list, whether the control was created dynamically or not.
Here's my code in the .aspx page:
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="testcode.aspx.cs" Inherits="testcode" %>
2
3 "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml" >
6 "server">
7 Untitled Page
8 9
10 "form1" runat="server">
11
12 "DropDownList1" runat="server" AutoPostBack="true">
13 1
14 2
15
16
17
18 "DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="test">
19 1
20 2
21
22
23 24 25
So I created two dropdownlists, for DropDownList1 I set all the desired attributes except for the onchange attribute statically. And for DropDownList2 I set all the attributes statically including the "OnSelectedIndexChanged".
In my code behind I attempted to change the attributes for DropDownList1 like so:
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class testcode : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 DropDownList1.Attributes.Add("onchange", "");
17 }
18
19 protected void test(object sender, EventArgs e)
20 {
21 Response.Write("works!");
22 }
23 }
When I ran this code, DropDownList2 fine worked because everything was declared statically, but DropDownList1 still does not work. DropDownList1 does cause a page refresh or a post back when I change the selected item, but does not call the "test" function.
Please note, in line 16 of the code above, if I change ("onchange", ""); to ("onchange", "test"); that makes Dropdownlist1 not even cause a postback.
Please help, I desperately need this done.
Thank you,
Shivam.