如何使网格可选
问题描述:
您好。我有GridView,我想让行可选。但是我有错误EnableEventValidation =true。如何使用RegisterForEventValidation解决这个问题?
C#Net.Framework 2.0
Hi. I Have GridView and I want to make the row selectable . But I have error "EnableEventValidation="true" . How to solve this problem using RegisterForEventValidation ?
C# Net.Framework 2.0
// Button opens grid
public void FindAdr_click(object sender, EventArgs e)
{
adres_data.SelectParameters.Remove(adres_data.SelectParameters["ul"]);
adres_data.SelectParameters.Add("ul", adr_name.Text.ToString());
adres_data.SelectParameters["ul"].DefaultValue = adr_name.Text.ToString();
}
// RowDataBound
protected void adrTabl_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
e.Row.Style["cursor"] = "hand";
e.Row.Attributes["onclick"] = _jsSingle;
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
}
}
}
// Select row
protected void adrTabl_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow selectedRow = adrTabl.SelectedRow;
adres.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text;
adresF.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text;
}
答
+ e.Row.RowIndex;
e.Row。 Style [cursor] =hand;
e.Row.Attributes [onclick] = _jsSingle;
e.Row.Attributes [onmouseover] =this.style.cursor = 'pointer'; this.style.textDecoration ='underline';;
e.Row.Attributes [onmouseout] =this.style.textDecoration ='none';;
}
}
}
//选择行
protected void adrTabl_SelectedIndexChanged(object sender,EventArgs e)
{
GridViewRow selectedRow = adrTabl.SelectedRow;
adres.Text = selectedRow.Cells [1] .Text +,,+ selectedRow.Cells [2] .Text;
adresF.Text = selectedRow.Cells [1] .Text +,,+ selectedRow.Cells [2] .Text;
}
" + e.Row.RowIndex); e.Row.Style["cursor"] = "hand"; e.Row.Attributes["onclick"] = _jsSingle; e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';"; e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';"; } } } // Select row protected void adrTabl_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow selectedRow = adrTabl.SelectedRow; adres.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text; adresF.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text; }
如果您不需要验证网站上的事件通过asp.net 2.0 newely添加功能。
由于事件验证功能,无效的PostBack或CallBack参数错误基本上会提高。 EventValidation功能是ASP.NET 2.0中的一项新功能,它提供了额外级别的检查,以验证来自客户端上的控件的回发是否真的来自该控件,而不是来自使用跨站点脚本注入等内容的恶意攻击者试图操纵事物。这是我们越来越多地在编程模型中添加深度级安全性的整体策略的一部分 - 这样即使开发人员忘记添加自己的安全检查,开发人员也可以保证安全。
现在,*当您触发click事件并且对象重新绑定或者在Page_Load事件中更改了其属性或者有人试图通过跨站点脚本攻击您的系统时,可能会发生无效的PostBack或CallBack参数错误。 *每次.Net Framework呈现一个页面,然后它为所有控件关联一个唯一的Guid。绑定gridview或repeater时,每个数据绑定框架都会为控件关联一个新的guid。因此,每当你发射事件时,确保Page_Load事件不会改变控件,因为如果控件改变了它,它将有一个不同的Guid,它们实际上已经开启了事件以进行回发。以下是此错误的一些情况。
1)GridView中的无效回发或回调参数问题可能是:您正在将Page_Load事件中的数据与对象数据源或手动绑定功能调用。这将使您的GridView在任何控件的每个事件触发时绑定数据。当您使用OnRowCommand触发任何GridView命令时,在RowCommand触发之前,您的GridView将重新绑定,并且其中的所有控件都将分配给新的id。因此RowCommand无法获取已触发事件的项目。 GridView中无效回发或回调参数的解决方案:您可以在此if条件下绑定数据。
if you don't need the events on the site to be validated by asp.net 2.0 newely added feature.
Invalid PostBack or CallBack argument error is basically raise because of Event Validation feature. The EventValidation feature is a new feature in ASP.NET 2.0, and provides an additional level of checks to verify that a postback from a control on the client is really from that control and not from someone malicious using something like a cross-site script injection to try and manipulate things. It is part of our overall strategy of increasingly adding security in depth levels to the programming model -- so that developers can be secure by default even if they forget to add security checks of their own.
Now, *Invalid PostBack or CallBack argument error may occur when you are firing click event and the object is rebinding or its properties are changed in Page_Load event or someone is trying to hack into your system with cross site scripting.* Each time .Net Framework render a page then it associate a unique Guid for all the controls. When binding a gridview or repeater, on each databind framework will associate a new guid for the contorl. So every time when you are firing event make sure Page_Load event does not change the control, because if the control changed the it will have a different Guid which have acutally fired the event for postback. Here are some scenario with this error.
1) Invalid Postback or Callback argument in GridView Problem may be: You are binding data in Page_Load event with either Object Data Source or Manual Binding with function call. This will make your GridView bind data on every event fire of any control. When you are firing any GridView command with OnRowCommand, before RowCommand fire your GridView will rebind and all control within it will be assigned to new id. So RowCommand could not get the item which have fired the event. Solution for Invalid Postback or Callback argument in GridView: You can bind your data within this if condition.
if (!IsPostBack)
{
//Your code for Bind data
}