I have a gridview in an ajax update panel. I have set the different button events as AsyncPostBackTriggers but I want the select button to open a child web page so it has to be a postback. I tried the following:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowCancelingEdit" />
<asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowEditing" />
<asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowUpdated" />
<asp:AsyncPostBackTrigger ControlID="gvClients" EventName="RowUpdating" />
<asp:AsyncPostBackTrigger ControlID="gvClients" EventName="Sorted" />
<asp:AsyncPostBackTrigger ControlID="gvClients" EventName="Sorting" />
<asp:PostBackTrigger ControlID="gvClients" />
</Triggers>
I recieved the following error:" System.ArgumentException: Control with ID 'gvClients' cannot be registered through both RegisterAsyncPostBackControl and RegisterPostBackControl. This can happen if you have conflicting triggers associated with the target control."
I tried accessing the select button from code behind and setting it as a trigger.
This is the code:
protected void gvClients_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnDtls = (Button)e.Row.Cells[0].Controls[2];
string btnDtlsId = btnDtls.ID;
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = btnDtlsId;
UpdatePanel1.Triggers.Add(trigger);
}
}
In debugging I saw that the ID for the button is "ctl01" but I'm getting this error: "A control with ID 'ctl01' could not be found for the trigger in UpdatePanel 'UpdatePanel1'". Is there a way of accessing a control field select button and setting it as a PostBackTrigger?
Since the button is inside a template, its final id is different and you can get it from the UniqueID property. http://msdn.microsoft.com/en-us/library/system.web.ui.control.uniqueid.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.