iframe中具有asp:GridView和SQLDataSource的表(aspx站点)正在增长,该表在父站点中的事件上刷新。
我已经添加了通过向其添加ActionCommand“删除,更新,编辑”来编辑GridView的可能性。为此,我向SQLDataSource添加了UpdateCommand。
删除有效-更新无效。
问题是,我得到了System.ArgumentException:具有未经验证的PostBack或Callbackargument。 当我将asp:CommandField更改为“ ButtonType” =“ Link”时,没有页面验证错误,但是当我将“ ButtonType”更改为“ Image”时,我得到了页面验证错误(请参见屏幕截图)。 两个ButtonType-Selection都不更新数据。
我已经向其中添加了UpdateParamaters节,但是它没有任何效果-相同的错误。我已经在页面顶部添加了EnableEventValidation =“ false”-错误消失了(就像ButtonType = Link一样),但是不会执行任何更新。
<asp:GridView DataKeyNames="id" CssClass="tableStyle" ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField ReadOnly="true" DataField="BelDat" HeaderText="Created on" SortExpression="BelDat" DataFormatString="{0:yyyy-MM-dd}" />
<asp:BoundField ReadOnly="true" DataField="PersNr" HeaderText="Pers No." SortExpression="PersNr" />
<asp:BoundField ReadOnly="true" DataField="lblPortfolio" HeaderText="Portfolio" SortExpression="lblPortfolio" />
<asp:BoundField ReadOnly="true" DataField="lblProject" HeaderText="Project" SortExpression="lblProject" />
<asp:BoundField ReadOnly="true" DataField="lblPSPElement" HeaderText="Element" SortExpression="lblPSPElement" />
<asp:BoundField ReadOnly="true" DataField="PSPElement" HeaderText="CC/Contract/PSP Element" SortExpression="PSPElement" />
<asp:BoundField DataField="Text50Stellen" HeaderText="Description" SortExpression="Text50Stellen" />
<asp:BoundField ReadOnly="true" DataField="Menge" HeaderText="Hours" SortExpression="Menge" DataFormatString="{0:n1}" />
<asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/cancel.png" DeleteImageUrl="~/Images/trash.png" EditImageUrl="~/Images/edit.png" ShowDeleteButton="True" ShowEditButton="True" UpdateImageUrl="~/Images/save.png" />
</Columns>
<EmptyDataTemplate>
(nothing has been logged in this month)
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" UpdateCommand="UPDATE timesheet SET Text50Stellen=@Text50Stellen WHERE id=@id" DeleteCommand="DELETE FROM timesheet WHERE id=@id" ConnectionString="<%$ ConnectionStrings:DP_TimeSheetConnectionString %>">
<UpdateParameters>
<asp:Parameter Name="Text50Stellen" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
这是我在Page_Load后面的代码部分中的代码:
public void refreshDataGrid()
{
SqlDataSource1.ConnectionString = MyConfigurationManager.prdSqlServerString;
SqlDataSource1.SelectCommand = @"
SELECT [id],
[username],
[BuDat],
[BelDat],
[PersNr],
[SendKst],
[Menge],
[Lar],
ISNULL([EmpfKst],'')+
ISNULL([EmpfAufn],'')+
ISNULL([EmpfPSPE],'') as PSPElement,
[EmpfKundenauftrag],
[Po],
[EmpfNetzplan],
[EmpfVorgang],
[Text50Stellen],
[lblPortfolio],
[lblProject],
[lblPSPElement]
FROM [timesheet]
WHERE username='";
SqlDataSource1.SelectCommand += new AuthenticationService().getUsername().Trim() + "' ";
if (Request.QueryString["month"] != null && Request.QueryString["year"] != null)
{
SqlDataSource1.SelectCommand += " AND MONTH(BuDat)=" + Request.QueryString["month"] + " AND YEAR(BuDat)=" + Request.QueryString["year"] + " ";
GridView1.Columns[GridView1.Columns.Count - 1].Visible = false;
}
else
{
SqlDataSource1.SelectCommand += " AND MONTH(BuDat)=MONTH(GetDate()) AND YEAR(BuDat)=YEAR(GetDate()) ";
}
SqlDataSource1.SelectCommand += " ORDER BY id DESC ";
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
refreshDataGrid();
}
问题是,当我在刷新asp:DataGrid之前要求if(!IsPostBack)时,表未加载
[ArgumentException: Ungültiges Postback- oder Callbackargument. Die Ereignisvalidierung wird mithilfe von <pages enableEventValidation="true"/> in der Konfiguration oder mithilfe von <%@ Page EnableEventValidation="true" %> auf einer Seite aktiviert. Aus Sicherheitsgründen überprüft dieses Feature, dass Argumente für Postback- oder Callbackereignisse von dem Serversteuerelement ausgehen, von dem sie ursprünglich gerendert wurden. Wenn die Daten gültig sind und erwartet wurden, verwenden Sie die ClientScriptManager.RegisterForEventValidation-Methode, um die Postback- oder Callbackdaten für die Validierung zu registrieren.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +9756058
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +108
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +29
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
S.th。我发现: 当我将asp:CommandField更改为以下代码时-PageValidation错误消失了,但更新不起作用:
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
EditText="<img src='Images/edit.png' style='border-width:0' />"
DeleteText="<img src='Images/trash.png' style='border-width:0' />"
CancelText="<img src='Images/cancel.png' style='border-width:0' />"
UpdateText="<img src='Images/save.png' style='border-width:0' />"
/>
答案 0 :(得分:0)
我不确定现在有什么不同,但现在可以与Tetsuya Yamamotos的提示一起使用。
if(!IsPostBack)GridView1.DataBind();
onmessage = function(event){
var v1 = event.data.key1 ;
var v2 = event.data.key2;
}