S
studio60podcast
I'm not sure I can do this, but here is what I'm trying to
accomplish...
I have a WebUserControl that has a single control - a DropDownList -
called BoundDL. In that control, I have methods that will bind that
control to a DataTable based on other properties that are set.
I have another page, test.aspx, that registers this UserControl and
sets it's properties. The trick is, I want to do AutoPostback on the
DDL in the user control and provide information from that event back
to the test.aspx page. I thought the best way to accomplish this
would be through a public delegate and event, but it's not working.
It says that the object reference was not set to an instance of an
object. Here is some code:
BoundDL.ascx:
<asp
ropDownList ID="BoundDL" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="BoundDL_SelectedIndexChanged" />
BoundDL.ascx.cs:
public delegate void IndexChangedEventHandler(int value);
public event IndexChangedEventHandler IndexChanged;
protected void BoundDL_SelectedIndexChanged(object sender, EventArgs
e)
{
IndexChanged(Int32.Parse(BoundDL.SelectedValue));
}
test.aspx:
<%@ register tagprefix="admin" tagname="BoundDL" src="BoundDL.ascx" %>
<asp:Label ID="Label1" runat="server" Text="Event" />
<admin:BoundDL ID="dlEvent" runat="server" />
test.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
dlEvent.IndexChanged += new
BoundDL.IndexChangedEventHandler(dlEvent_IndexChanged);
}
protected void dlEvent_IndexChanged(int value)
{
Label1.Text += value.ToString();
}
It's failing on
IndexChanged(Int32.Parse(BoundDL.SelectedValue));
Have I missed something? This is the first time I've used delegates
in ASP.NET. I just followed an example I had working in Windows
Forms.
Thanks for the help!
Jason
accomplish...
I have a WebUserControl that has a single control - a DropDownList -
called BoundDL. In that control, I have methods that will bind that
control to a DataTable based on other properties that are set.
I have another page, test.aspx, that registers this UserControl and
sets it's properties. The trick is, I want to do AutoPostback on the
DDL in the user control and provide information from that event back
to the test.aspx page. I thought the best way to accomplish this
would be through a public delegate and event, but it's not working.
It says that the object reference was not set to an instance of an
object. Here is some code:
BoundDL.ascx:
<asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
OnSelectedIndexChanged="BoundDL_SelectedIndexChanged" />
BoundDL.ascx.cs:
public delegate void IndexChangedEventHandler(int value);
public event IndexChangedEventHandler IndexChanged;
protected void BoundDL_SelectedIndexChanged(object sender, EventArgs
e)
{
IndexChanged(Int32.Parse(BoundDL.SelectedValue));
}
test.aspx:
<%@ register tagprefix="admin" tagname="BoundDL" src="BoundDL.ascx" %>
<asp:Label ID="Label1" runat="server" Text="Event" />
<admin:BoundDL ID="dlEvent" runat="server" />
test.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
dlEvent.IndexChanged += new
BoundDL.IndexChangedEventHandler(dlEvent_IndexChanged);
}
protected void dlEvent_IndexChanged(int value)
{
Label1.Text += value.ToString();
}
It's failing on
IndexChanged(Int32.Parse(BoundDL.SelectedValue));
Have I missed something? This is the first time I've used delegates
in ASP.NET. I just followed an example I had working in Windows
Forms.
Thanks for the help!
Jason