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.
Related
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
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>
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=" ">
<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=" ">
<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>
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>
I Have this type of code in Gridview in UpdatePanel..
Now when I Checked CheckBox then it fire its OnSelectedIndexChanged event But When I Select two or three CheckBox and then uncheck any checkbox among selected then it's
OnSelectedIndexChanged event is not fired..why this happen
<asp:Label ID="lbltempCity" runat="server" Text="City"></asp:Label>
<asp:CheckBoxList ID="lst" AutoPostBack="true" runat="server" Width="100px" Height="100px" BorderWidth="1px" BackColor="White" OnSelectedIndexChanged="hello">
<asp:ListItem>Test1</asp:ListItem>
<asp:ListItem>Test2</asp:ListItem>
<asp:ListItem>Test1</asp:ListItem>
<asp:ListItem>Test2</asp:ListItem>
</asp:CheckBoxList>
<asp:DropDownExtender ID="DropDownExtender1" runat="server" DropArrowWidth="300px" TargetControlID="lbltempCity" DropDownControlID="lst">
</asp:DropDownExtender>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Eval("tempCity") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
I tested the code it is working fine. May be cause of problem is in grid or any other control in your page. post the full code so that we can help.