checkbox inside a gridview within updatepanel - asp.net

I have a gridview with a checkbox in first column. I set checkbox property of autopostback="true". The gridview is inside the updatepanel. When checkbox is checked i want to make one panel as visible, which panel is outside the update panel. I check the code with check point, which is go through the code, but its not working. Can any one help me?..
Thanks in advance.
My code is here for your reference...
HTML Code:
<asp:Panel ID="ploperation" runat="server" CssClass="plop" Visible="False">
<asp:LinkButton ID="lbtnasspam" runat="server" CssClass="panelbtn" Font-Names="Calibri"
Font-Size="14px" Font-Underline="False" OnClick="lbtnasspam_Click">Report As Spam</asp:LinkButton>
</asp:Panel>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:GridView ID="gvmail" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" OnCheckedChanged="chkchild_CheckedChanged"/>
</ItemTemplate>
<ItemStyle Width="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
C# Code:
protected void chkchild_CheckedChanged(object sender, EventArgs e)
{
ploperation.Visible = true;
}

You can use initializeRequest - this event is raised when an asynchronous post back occurs(When you check the checkbox in your gridview it initiates an async postback because it's inside an update panel).
Just change ploperation to a div instead of <asp:Panel and you can use javascript to show/hide it:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(initializeRequest);
function initializeRequest(sender, args) {
document.getElementById('ploperation').style.display = 'block';
}
</script>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:GridView ID="gvmail" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" />
</ItemTemplate>
<ItemStyle Width="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<div id="ploperation" style="display:none;" runat="server">
<asp:LinkButton ID="lbtnasspam" runat="server" CssClass="panelbtn" Font-Names="Calibri"
Font-Size="14px" Font-Underline="False" OnClick="lbtnasspam_Click">Report As Spam</asp:LinkButton>
</div>
</form>
Alternatively you can stick to the way you've done it, just place <asp:Panel inside UpdatePanel -> ContentTemplate

update panel does partial page loading....
check link
so if you want to show your panel than include it also in your update panel.

Put the UpdatePanel on the control you want to change, not on the GridView. Do not forget to Reference the GridView on the Triggers section. For example, if you want to change a label text use the following code:
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvmail" />
</Triggers>
</asp:UpdatePanel>
<asp:GridView ID="gvmail" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" OnCheckedChanged="chkchild_CheckedChanged"/>
</ItemTemplate>
<ItemStyle Width="15px" />
</asp:TemplateField>
</Columns>
</asp:GridView>

Related

Textbox gridview in asp:asyncpostbacktrigger with updatepanel

I have a textbox in a gridview templatefield and I want to handle its TextChanged event. The problem is using the UpdatePanel trigger I get the following message?
A control with ID 'txtQtd' could not be found for the trigger in UpdatePanel 'UpdatePanel1'
How can I incorporate this control into updatepanel?
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="Origin" ItemStyle-Width="8%" />
<asp:BoundField DataField="Destiny" ItemStyle-Width="8%"/>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtQtd" AutoPostBack="true" OnTextChanged="txtQtd_TextChanged" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Factor" ItemStyle-Width="8%" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtQtd" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
what you could do is put an invisible button that calls the txtQtd_TextChanged method from javascript, that is, you put the onchange property inside the textbox and when this is executed you will call the button with document.getElementById (MainContent_btn).click();
It's just an idea

Gridview inside updatepanel

How do i update gridView inside UpdatePanel.
My delete button i okay. But I have to refresh page to see changes.
btn Button and litTest is for checking updatePanel.
I hope anyone can help me whats wrong...
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" EnablePartialRendering="true" runat="server">
<ContentTemplate>
<asp:Literal ID="litTest" runat="server" />
<asp:GridView
ID="GridViewBruger"
CssClass="TableSort"
runat="server"
CellPadding="4"
GridLines="Horizontal"
AutoGenerateColumns="False"
width="500"
onrowcommand="GridViewCase_RowCommand">
<Columns>
<asp:BoundField DataField="FilePath" />
<asp:BoundField DataField="File" ItemStyle-HorizontalAlign="Center" HeaderText="File" ItemStyle-Width="200px" HeaderStyle-CssClass="header"/>
<asp:BoundField DataField="Date" ItemStyle-HorizontalAlign="Center" HeaderText="Date"/>
<asp:buttonfield buttontype="Image" ItemStyle-HorizontalAlign="Center" ImageUrl="~/img/trash.png" commandname="Del" text="Slet" HeaderText="Delete"/>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btn" Text="testUpdatePanel" runat="server" OnClick="btn_Click" />
Thanks!!
By calling the GridViewBruger.DataBind() on code behind the GridView will be updated.
Also if you add the update button, inside the update panel, and on code behind also just call the DataBind() also the grid view will be updated.
.....
</asp:GridView>
<asp:Button ID="btn" Text="testUpdatePanel" runat="server" OnClick="btn_Click" />
</ContentTemplate>
</asp:UpdatePanel>

Gridview TemplateField checkbox postback behavior in asp.net

I have GridView inside UpdatePanel and UpdateMode of the UpdatePanel is set to conditional.
Gridview contains asp:CheckBox as TemplateField and rest of the columns are boundfields which are dynamically created.
Checbox AutoPostBack is set to true and I update a datatable (which is inside session) based on checkbox value.
Here is markup:
<asp:GridView ID="ObjList" runat="server" CssClass="ObjList" AutoGenerateColumns="false" OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False">
<Columns>
<asp:TemplateField HeaderText="&nbsp">
<HeaderTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" />
<asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkRow" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Selection")%>'
OnCheckedChanged="ChkRow_OnCheckChange" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In Deployed version only:
Whenever user click 2 or more checkboxes in fast speed. Postback of first checkbox fires and rest of checkboxes get unchecked. How can I control this behavior?
When Local IIS is running:
Postback of every checkbox fires.
In Firebug debugging it is noticed that Postback of first checkbox takes quite a time.
Please tell me how can I avoid this situation.
Try this
<asp:GridView ID="ObjList" runat="server" CssClass="ObjList" AutoGenerateColumns="false"
OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False">
<Columns>
<asp:TemplateField HeaderText="&nbsp">
<HeaderTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" />
</HeaderTemplate>
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkRow" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Selection")%>'
OnCheckedChanged="ChkRow_OnCheckChange" />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

ASP.NET - Adding an UpdatePanel trigger to a LinkButton inside a gridview

I was trying to update the content of a modal dialog, and this code works for me:
<asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
<asp:UpdatePanel ID="upNewUpdatePanel" runat="server">
<ContentTemplate>
<asp:Label ID="updateLabel" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="updateSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
However, when I try to place the LinkButton inside a gridview, like so:
<asp:GridView ID="grdListUsers" runat="server" AutoGenerateColumns="false" AllowPaging="false" OnRowDataBound="grdRowDefListUsers" CssClass="mGrid" EmptyDataText="No users.">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Nome" HeaderStyle-Width="300" />
<asp:BoundField DataField="Login" HeaderText="Login" HeaderStyle-Width="300" />
<asp:TemplateField HeaderText="Options" HeaderStyle-Width="75" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
</asp:TemplateField>
</Columns>
</asp:GridView>
This does not work, I get an error saying: A control with ID 'updateSomething' could not be found for the trigger in UpdatePanel 'upNewUpdatePanel'.
How can I use the ImageButton inside the gridview?
Try and add the asp:AsyncPostBackTrigger to the asp:GridView's OnRowCommand event and handle the link button click in that event
<asp:GridView ID="grdListUsers" runat="server" onRowCommand="grdListUsers_RowCommand">
<asp:TemplateField>
<asp:LinkButton ID="updateSomething" CommandName="update-something" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'/>
</asp:TemplateField>
</asp:GridView>
and in the cs create the event like this
protected void grdListUsers_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "update-something")
{
grdListUsers.SelectedIndex = Convert.ToInt32(e.CommandArgument);
}
}
You could add a trigger of the gridview
<Triggers>
<asp:PostBackTrigger ControlID="gridview1" />
</Triggers>
Add another Update Panel surrounding your link button just like below.
<asp:GridView ID="grdListUsers" runat="server" AutoGenerateColumns="false" AllowPaging="false" OnRowDataBound="grdRowDefListUsers" CssClass="mGrid" EmptyDataText="No users.">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Nome" HeaderStyle-Width="300" />
<asp:BoundField DataField="Login" HeaderText="Login" HeaderStyle-Width="300" />
<asp:TemplateField HeaderText="Options" HeaderStyle-Width="75" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:UpdatePanel ID="aa" runat="server">
<ContentTemplate>
<asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="updateSomething"/>
</Triggers>
</asp:UpdatePanel>
</asp:TemplateField>
</Columns>
</asp:GridView>
You could set the UpdatePanel's UpdateMode to Conditional and update it manually from the UpdateButton_Click-Handler:
<asp:UpdatePanel ID="UdpFormPanel" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false" >
LinkButton's Click-Event handler:
Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As EventArgs)
'blah....
upNewUpdatePanel.Update()
End Sub

ASP Updatepanel inside content disappears

I have an update panel with a gridview and some radios inside it. Senario is that when user select a radio, some bottoms get visible. But after radio eventhandler is trigered, updatepanel contents get dissapered. Any idea about this problem?
<asp:ScriptManager ID="scriptManager_main" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatePanel_main" runat="server">
<ContentTemplate>
<asp:GridView ID="gridView_stLists" runat="server" AutoGenerateColumns="False" CellPadding="3"
BorderStyle="NotSet" CssClass="table_layout" Width="500">
<RowStyle CssClass="table_body" />
<Columns>
<asp:TemplateField HeaderStyle-Width="20">
<ItemTemplate>
<asp:RadioButton ID="rdBtn_stdl" runat="server" OnCheckedChanged="rdBtn_stdl_CheckedChanged"
AutoPostBack="True" GroupName="stdl" value='<%# Eval("uri") %>' />
</ItemTemplate>
<HeaderStyle Width="20px" />
</asp:TemplateField>
...
The RadioButton is doing an AutoPostBack. Are you rebinding to the GridView after postback and thus overridding your changes/state? Only DataBind if !IsPostBack and this might address the issue.

Resources