I have two drop down boxes and one list box. My client wants the patrons to either search for authors from a drop down box that lists all the authors or from the list box that displays a list of authors based on the genre. The individual authors add button does not work. I get an error message that states: Exception has been thrown by the target of an invocation.
Here is my code:
How do I resolve the error and meet my client's requirement to allow library patrons to use either button? Both buttons need to fire the same event.
Here is my code:
Code:
protected void AddAnAuthor(object sender, EventArgs e)
{
AddAuthors_ds.Insert();
OneAuthorList_lb.ClearSelection();
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void AddAuthors(object sender, EventArgs e)
{
AddAuthors_ds.Insert();
AuthorList_lb.ClearSelection();
Response.Redirect(Request.Url.AbsoluteUri);
}
Code:
<asp:DropDownList runat="server" ID="OneAuthorList_lb" style="float:left;" DataSourceID="AuthorList" DataTextField="AuthorName" DataValueField="AuthorName" onselectedindexchanged="AddOneAuthor_SelectedIndexChanged"
AutoPostBack="True" AppendDataBoundItems="true" />
<asp:ImageButton ImageUrl="add.png" OnMouseOver="addHover.png'" runat="server" ID="AddAnAuthor" style="float:left; margin-left:5px;" OnClick="AddAnAuthor" />
<asp:DropDownList runat="server" ID="AuthorsList"
style="float:left;" DataSourceID="AuthorsList_ds"
DataTextField="AuthorName" DataValueField="AuthorName"
onselectedindexchanged="AuthorsList_SelectedIndexChanged"
AutoPostBack="True" AppendDataBoundItems="true">
<asp:ListItem Text="Select Genre" Value="~Select Genre~" />
</asp:DropDownList>
<asp:ImageButton ImageUrl="add.png'" ToolTip="Add Authors From List" runat="server" ID="btnAddAuthors" style="float:left; margin-left:5px;" OnClick="btnAddAuthorsListed" />
<asp:ListBox runat="server" ID="AuthorList" DataTextField="AuthorName"
DataValueField="UserID" DataSourceID="Authors" SelectionMode="Multiple" AppendDataBoundItems="true" />