页面 Repeater 中用了 ImageButton 报错(回发或回调参数无效)

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. 

回发或回调参数无效事件验证使用的是启用<enableeventvalidation =“真正的”/ > < % @页面配置或enableeventvalidation =“真实”% >的一页为了安全目的此功能验证回发或回调事件的参数来自服务器控制最初呈现他们如果数据是有效的和预期使用clientscriptmanager.registerforeventvalidation方法以便注册回发或回调数据验证

解决方案:在Page_Load加上一个 if(!IsPostBack)判断后,再绑定数据就可以了。

问题代码:

if (!IsPostBack)
{
string strNick = "杯口留香旗舰店";

//绑定计划下拉框
IList<DCCampaign> mDCCampaignLst = base.DCCampaignService.GetAllByNick(strNick);
drpCampaign.DataSource = mDCCampaignLst;
drpCampaign.DataTextField = "title";
drpCampaign.DataValueField = "campaign_id";
drpCampaign.DataBind();

}

//数据绑定要放在 if (!IsPostBack) 里面,不然会
string strCampaignTitle = drpCampaign.SelectedItem.Text.Trim();
this.BindData(strNick, strCampaignTitle, "", "");

 

正确代码:

if (!IsPostBack)
{
string strNick = "杯口留香旗舰店";

//绑定计划下拉框
IList<DCCampaign> mDCCampaignLst = base.DCCampaignService.GetAllByNick(strNick);
drpCampaign.DataSource = mDCCampaignLst;
drpCampaign.DataTextField = "title";
drpCampaign.DataValueField = "campaign_id";
drpCampaign.DataBind();

//数据绑定要放在 if (!IsPostBack) 里面,不然会
string strCampaignTitle = drpCampaign.SelectedItem.Text.Trim();
this.BindData(strNick, strCampaignTitle, "", "");
}

 

posted @ 2012-08-31 12:30  xust  阅读(246)  评论(0)    收藏  举报