I have two Drop down lists : (ddlUserID and ddlUserID0)
ddlUserID is filled using sqldatasource during page load.
ddlUserID0 is filled based on the selection from ddlUserID using the following javascript code
function AppendUsers()
{
var opt = document.createElement("Option");
var i =document.getElementById("ddlUserID").selectedIndex;
opt.text = document.getElementById("ddlUserID").options[i].text;
opt.value = i;
document.getElementById("ddlUserID0").options.add(opt);
}
The above code works fine BUT when I try to save or if any postback happens, I get a long error message as follows :
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback
or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Please remember to click " Mark As Answer " on the post that helps you. This can be beneficial to other community members reading the thread.
Good Luck
human2x
Member
118 Points
81 Posts
my dropdownlist generates an error after postback
Mar 31, 2012 11:31 PM|LINK
Hi all
I have two Drop down lists : (ddlUserID and ddlUserID0)
ddlUserID is filled using sqldatasource during page load.
ddlUserID0 is filled based on the selection from ddlUserID using the following javascript code
function AppendUsers() { var opt = document.createElement("Option"); var i =document.getElementById("ddlUserID").selectedIndex; opt.text = document.getElementById("ddlUserID").options[i].text; opt.value = i; document.getElementById("ddlUserID0").options.add(opt); }The above code works fine BUT when I try to save or if any postback happens, I get a long error message as follows :
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
bakra
Member
342 Points
59 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 01:10 AM|LINK
Look at the code in the top of your aspx page and change EnableEventValidation="true" to EnableEventValidation="false".
If you dont see that code in your aspx page then look for it in your webconfig file and change it there
Please "Mark as Answer" if this resolved your issue
roopeshreddy
All-Star
20143 Points
3327 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 02:03 AM|LINK
Hi,
You can try registering you event!
http://blogs.msdn.com/b/amitsh/archive/2007/07/31/why-i-get-invalid-postback-or-callback-argument-errors.aspx
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
human2x
Member
118 Points
81 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 06:33 AM|LINK
Dear Bakra
Your answer stoped the compilation error but the filled drop down list (ddlUserID0) was reset and became blank.
bakra
Member
342 Points
59 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 11:55 AM|LINK
Hi haman2x
Can you ensure that you change the ClientIDMode of the the drop down list that is bound to the sql datasource (ddlUserID) to "Static" e.g.
<asp:DropDownList ID="ddlUserID" runat="server"
DataSourceID="sqlDatasource" DataTextField="textField"
DataValueField="valueField" ClientIDMode="Static">
</asp:DropDownList>
Please "Mark as Answer" if this resolved your issue
human2x
Member
118 Points
81 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 01:17 PM|LINK
I tried that but it still gets reset and becomes blank
bakra
Member
342 Points
59 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 02:29 PM|LINK
Can you ensure that you change the ClientIDMode of the the other drop down list as well (ddlUserID0) to "Static"
If changing both drop down lists to static does not work can you post your full code as this would be more helpful in diagnosing the problem
Pleas "Mark as Answer" if this resolved your issue
human2x
Member
118 Points
81 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 08:48 PM|LINK
thanks bakra for your care
the full page code is below
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="CreateTask.aspx.vb" EnableEventValidation="false" Inherits="CreateTask" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="Styles/NewTask.css" rel="stylesheet" type="text/css" /> </head> <body style="direction: rtl"> <form id="form1" runat="server"> <div id="wrapper"> <div id="header"> </div> <div id="main"> <table width="100%" border="0" id="NewTask"> <tr> <th width="18%" align="left" scope="row"> TASK NAME</th> <td colspan="3" align="right"> <asp:TextBox ID="txtTaskName" runat="server" Height="1.5em" Width="95%"></asp:TextBox> </td> </tr> <tr> <th align="left" scope="row" > TASK DATE</th> <td colspan="3" align="right" style="direction: ltr; margin-left: 80px;"> <asp:TextBox ID="txtActionDate" runat="server" Height="1.5em" Width="30%"></asp:TextBox> </td> </tr> <tr> <th align="left" scope="row" >DURATION</th> <td colspan="3" align="right"> <asp:TextBox ID="txtDuration" runat="server" Height="1.5em" Width="10%"></asp:TextBox> <asp:DropDownList ID="ddlTimeUnit" runat="server" Height="1.5em"> <asp:ListItem Value="1">MIN</asp:ListItem> <asp:ListItem Value="60">HOUR</asp:ListItem> <asp:ListItem Value="1440">DAY</asp:ListItem> <asp:ListItem Value="43200">MONTH</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <th align="left" scope="row" >TASK TO</th> <td width="35%" align="right" > <asp:DropDownList ID="ddlUserID" runat="server" AppendDataBoundItems="True" Height="1.5em" Width="80%" DataSourceID="sdsUsers" DataTextField="UserName" DataValueField="UserID" onchange="AppendUsers();" ClientIDMode="Static" > </asp:DropDownList> </td> <td width="26%" align="right" > <asp:DropDownList ID="ddlUserID0" runat="server" Height="1.5em" Width="181px" ClientIDMode="Static" > </asp:DropDownList > </td> <td width="21%" align="right" > <asp:Button ID="Button1" runat="server" Text="DELETE" onclientclick="return RemoveUser();" Width="49px" /> </td> </tr> <tr> <th align="left" scope="row" >APPOINTMENT</th> <td colspan="3" align="right"> <asp:TextBox ID="txtActionDate0" runat="server" Height="1.5em" Width="30%"></asp:TextBox> </td> </tr> <tr> <th align="left" scope="row" >TASK DETAILS</th> <td colspan="3" align="right"> <asp:TextBox ID="txtDetails" runat="server" Height="7em" TextMode="MultiLine" Width="95%"></asp:TextBox> </td> </tr> <tr> <th align="left" scope="row" >TASK NOTES</th> <td colspan="3" align="right"> <asp:TextBox ID="txtNotes" runat="server" Height="3em" TextMode="MultiLine" Width="95%"></asp:TextBox> </td> </tr> <tr> <th align="left" scope="row" > </th> <td colspan="3" align="right"> <asp:Button ID="cmdCreate" runat="server" Font-Size="Medium" Text="CREATE" Width="100px" /> <asp:Button ID="Button2" runat="server" Text="Button" /> </td> </tr> </table> </div> </div> <asp:SqlDataSource ID="sdsUsers" runat="server" ConnectionString="<%$ ConnectionStrings:tasksConnectionString %>" ProviderName="<%$ ConnectionStrings:tasksConnectionString.ProviderName %>" SelectCommand="SELECT UserID, UserName FROM users ORDER BY UserName"> </asp:SqlDataSource> </form> <script type="text/JavaScript"> function AppendUsers() { var opt = document.createElement("Option"); var i = document.getElementById("ddlUserID").selectedIndex; opt.text = document.getElementById("ddlUserID").options[i].text; opt.value = i; opt.sno = document.getElementById("ddlUserID0").options.length + 1; // var userID = document.getElementById("ddlUserID").value; // alert (userID); // document.getElementById("ddlUserID0").options.add(opt); //alert(document.getElementById("ddlUserID0").options.value); //alert(opt.value); //alert(opt.sno); x = document.getElementById("ddlUserID0"); alert(x.length); if (x.length == 0) { document.getElementById("ddlUserID0").options.add(opt); } else { var flag = 0; for (j = 1; j <= x.length; j++) { if (i == x.options[j - 1].value) { flag = 1; //the name is already available break; } } if (flag == 0) { // if the name does not exist on the list document.getElementById("ddlUserID0").options.add(opt); } } } function RemoveUser() { var x = document.getElementById("ddlUserID0") x.remove(x.selectedIndex); return false; } </script> </body> </html>bakra
Member
342 Points
59 Posts
Re: my dropdownlist generates an error after postback
Apr 01, 2012 11:26 PM|LINK
Add the following "onload" event to body tag in your html
<body onload="AppendUsers()"> //will call the function every time the page loads
Also add AutoPostBack="True" to your "ddlUserID" drop down list
<asp:DropDownList ID="ddlUserID" runat="server" AppendDataBoundItems="True" Height="1.5em" Width="80%"
DataSourceID="sdsUsers" DataTextField="UserName" DataValueField="UserID" onchange="AppendUsers();"
ClientIDMode="Static" AutoPostBack="True">
</asp:DropDownList>
Please "Mark as Answer" if this helped you
DotNetRaven
Member
236 Points
52 Posts
Re: my dropdownlist generates an error after postback
Apr 02, 2012 05:50 AM|LINK
Use AJAX Update Panel For both The DropDownList's
Good Luck