gpt4 book ai didi

c# - ImageButton 中的回发或回调参数无效

转载 作者:行者123 更新时间:2023-12-02 12:20:30 26 4
gpt4 key购买 nike

我的“删除按钮(图像按钮)”的单击事件有问题。我知道大家对此还有其他疑问,但我什么也不明白!

我没听懂没有答案!我做了所有其他问题中指定的所有内容!此页面中的其他事件使“重定向”到示例,效果很好!

我说清楚了吗?需要更多详细信息吗?堆栈跟踪还是更多代码?

错误是:

Invalid postback or callback argument. Event validation is enabled using 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.

我的页面:

<div id="Users" align="center">
<asp:Button ID="btnCreate" class="btn" Font-Bold="true" runat="server" OnClick="btnCreate_OnClick" />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" GridLines="None"
CssClass="table table-bordered table-striped" HeaderStyle-Font-Size="14px">
<Columns>
<asp:BoundField DataField="UserName" />
<asp:BoundField DataField="DisplayName" />
<asp:BoundField DataField="Email" />
<asp:BoundField DataField="ProfileName" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnEdit" ImageUrl="style/edit_16.png" runat="server" OnClick="btnEdit_OnClick" />
&nbsp;&nbsp;
<asp:ImageButton ID="btnDelete" ImageUrl="style/delete_16.png" runat="server" OnClick="btnDelete_OnClick" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>

我的事件:

protected void btnDelete_OnClick(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
string UserName = row.Cells[0].Text;

using (objConexao = new SqlConnection(strStringConexao))
{
using (objCommand = new SqlCommand(strDeleteUser, objConexao))
{
try
{
objConexao.Open();
objCommand.Parameters.AddWithValue("@UserName", UserName);
var objDataReader = objCommand.ExecuteReader();
}
finally
{
objConexao.Close();
}
}
}
}

我的Page_Load和CarregaGrid()

public void CarregaGrid()
{
var listaRequest = new UsersNDR().ConsultUsers();
if (listaRequest != null)
{
this.GridView1.DataSource = listaRequest;
this.GridView1.DataBind();

foreach (GridViewRow row in GridView1.Rows)
{
string idioma = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToString();

if (Session["idioma"].ToString() != null)
{
idioma = Session["idioma"].ToString();
}

ImageButton btnDelete = (ImageButton)row.FindControl("btnDelete");
ImageButton btnEdit = (ImageButton)row.FindControl("btnEdit");
btnDelete.ToolTip = Idioma.RetornaMensagem("btnDelete");
btnEdit.ToolTip = Idioma.RetornaMensagem("btnEdit");
}
}
}

protected void Page_Load(object sender, EventArgs e)
{
string idioma = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToString();

if (Session["idioma"].ToString() != null)
{
idioma = Session["idioma"].ToString();
}

Idioma.MudaCultura(idioma);
btnCreate.Text = Idioma.RetornaMensagem("btnCreate");
GridView1.Columns[0].HeaderText = Idioma.RetornaMensagem("UserName");
GridView1.Columns[1].HeaderText = Idioma.RetornaMensagem("DisplayName");
GridView1.Columns[2].HeaderText = Idioma.RetornaMensagem("email");
GridView1.Columns[3].HeaderText = Idioma.RetornaMensagem("ProfileName");
GridView1.Columns[4].HeaderText = Idioma.RetornaMensagem("Action");
CarregaGrid();
}

最佳答案

我相信在每次回发时重新绑定(bind)网格是问题所在,尝试将网格更改逻辑包装在 !IsPostBack 中,如下所示:

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string idioma = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToString();

if (Session["idioma"].ToString() != null)
{
idioma = Session["idioma"].ToString();
}

Idioma.MudaCultura(idioma);
btnCreate.Text = Idioma.RetornaMensagem("btnCreate");
GridView1.Columns[0].HeaderText = Idioma.RetornaMensagem("UserName");
GridView1.Columns[1].HeaderText = Idioma.RetornaMensagem("DisplayName");
GridView1.Columns[2].HeaderText = Idioma.RetornaMensagem("email");
GridView1.Columns[3].HeaderText = Idioma.RetornaMensagem("ProfileName");
GridView1.Columns[4].HeaderText = Idioma.RetornaMensagem("Action");
CarregaGrid();
}
}

关于c# - ImageButton 中的回发或回调参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18236589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com