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>
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
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 am facing little issue in my web application in asp.net.
i am receiving the below error :
Error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.
I have used Updatepanel and this error occurs when i try to do some 2-3 actions very quickly.
and when next time i try to do take some action my web application just hungs up.
Please suggest.
Thanks
In my case this was caused by having the 'Close' control within an Update Panel in the Modal Popup. I fixed it by creating a 'dummy' button outside of the Update Panel, and setting it as the 'CancelControlID' in the MPE attributes:
<asp:Button ID="btnDummyCloseWindow" runat="server" Style="visibility: hidden"/>
<ajaxToolkit:ModalPopupExtender ID="mpeWindow" runat="server" PopupControlID="pnlWindow"
TargetControlID="btnDummyOtherButton" BackgroundCssClass="modalBackground"
DropShadow="false" CancelControlID="btnDummyCloseWindow" />
You'll need to make sure the close button that is present within your Update Panel has actions assigned to it to close the window (e.g. mpeWindow.hide()).
It's also worth noting that I was also making use of the TargetControlID 'fix' too, where a dummy button is referenced, so ignore the TargetControlID attribute there.
I've solved the problem setting ScriptMode property of ScriptManager to Release instead of Debug
By default ScriptManager is set to Debug mode.
I had the same problem and solved by placing the ModalPopupExtender or the user control that uses ModalPopupExtender inside an update panel.
Which ever way you want to look at it, the problem is inherit in what I believe is a bug in AJAX.
The only way I was able to resolve this was to control your Sorting or Paging on the server side where you control or more specifically refresh the UpdatePanel along with making sure the ModalPopup has been kept visible!
The reason for the error is really because once you do a sort of page change on a GridView that's inside an UpdatePanel, the controls have been "lost" to the UpdatePanel.
A better explanation is here.
Here is a column from my GridView...
<asp:GridView ID="gvTETstudents" runat="server" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" ForeColor="#333333" Font-Size="Small" Width="100%"
DataSourceID="sdsTETstudents"
OnRowCreated="gvTETstudents_RowCreated"
OnRowDataBound="gvTETstudents_RowDataBound"
OnDataBound="gvTETstudents_DataBound">
<Columns>
..
..
<ItemTemplate>
<asp:UpdatePanel ID="upWEF1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWEFCLOSE" />
</Triggers>
<ContentTemplate>
...
...
<asp:Panel ID="pnlWEF2" runat="server" style="display:none;">
<table><tr><td>
<asp:Button ID="btnWEFshow" runat="server"
Text="ALL"
Font-Size="Small" Font-Names="Arial"
ToolTip="Click here to see all of this student's work experience feedback on file" />
<ajaxToolkit:ModalPopupExtender ID="mpeWEF" runat="server"
BackgroundCssClass="modalBackground"
OkControlID="btnWEFCLOSE"
PopupControlID="upWEF2"
TargetControlID="btnWEFshow">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEF2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlWEF3" runat="server" CssClass="pnlEndorsed">
<div id="Hdr" style="text-align: center">
<asp:Label ID="lblWEFHdr" runat="server">** CONTACT LOG **</asp:Label>
</div>
<div id="Bdy">
<table style="width:100%"><tr><td>
<asp:GridView ID="gvWEFContactLog" runat="server"
Font-Size="X-Small" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="8" AllowSorting="True" AutoGenerateColumns="False" Width="100%"
DataKeyNames="StudentContactLogID,Private,ApprenticeContactLogID"
DataSourceID="sdsWEF"
OnRowDataBound="gvWEFContactLog_RowDataBound"
OnPageIndexChanging="gvWEFContactLog_PageIndexChanging"
OnSorted="gvWEFContactLog_Sorted">
<Columns>
<asp:TemplateField HeaderText="First Entered" SortExpression="FirstEntered">
<ItemTemplate>
<asp:HiddenField ID="hfWEFStudCLid" runat="server" Value='<%# Eval("StudentContactLogID") %>' />
<asp:HiddenField ID="hfWEFAppCLid" runat="server" Value='<%# Eval("ApprenticeContactLogID") %>' />
<asp:HiddenField ID="hfPrivate" runat="server" Value='<%# Eval("Private") %>' />
<asp:HiddenField ID="hfNotes" runat="server" Value='<%# Eval("ContactNotes") %>' />
<asp:LinkButton ID="lnkWEFCLOG" runat="server"
Text='<%# Eval("FirstEntered","{0:d MMM yyyy HH:mm}") %>'></asp:LinkButton>
<a id="lnkDummy" runat="server" visible=false></a>
<ajaxToolkit:ModalPopupExtender ID="mpeWEFCLOG" runat="server"
OkControlID="btnWEFCLOSEview"
PopupControlID="upWEFCLOG"
TargetControlID="lnkWEFCLOG">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEFCLOG" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="pnlWEFCLOG" runat="server" class="pnlCLOG">
<asp:TextBox ID="txtWEFCLOG" runat="server"
Wrap="true"
TextMode="MultiLine"
Rows="10"
ReadOnly="true"
Width="98%">
</asp:TextBox>
<br />
<asp:Button ID="btnWEFCLOSEview" runat="server" Text="OK" Width="100%" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
<asp:BoundField Visible="False" DataField="StudentContactLogID" HeaderText="LogID"
InsertVisible="False" ReadOnly="True" SortExpression="StudentContactLogID">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="StaffName" HeaderText="Staff" ReadOnly="True" SortExpression="StaffName" />
<asp:TemplateField HeaderText="Contact Date Time" SortExpression="ContactDateTime">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactDateTime","{0:d MMM yyyy HH:mm}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Follow-Up Date" SortExpression="FollowUpDate">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("FollowUpDate","{0:d MMM yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Private" HeaderText="Private" SortExpression="Private" />
</Columns>
<EmptyDataTemplate>
No Current Entries
</EmptyDataTemplate>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="sdsWEF" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="spTETStudentContactLogView" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:Parameter Name="WEF" Type="string" DefaultValue="%" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr style="text-align: center">
<td style="text-align: left">
<asp:Button ID="btnWEFCLOSE" runat="server"
Text="CLOSE"
CausesValidation="false" Font-Bold="True" Width="61px" />
</td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</td></tr></table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
The major point of the code above is that I have a very deep GridView inside an UpdatePanel that's inside a ModalPopUp.
Now look at what I have inside that GridView:
OnPageIndexChanging
and
OnSorted
Inside the GridView, there is another ModalPopup and TextBox. Ignore that. That's only so the user can see the comments from the student's contact log as another popup window.
So if we now go to the code behind for the above two events:
protected void gvWEFContactLog_Sorted(object sender, EventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
protected void gvWEFContactLog_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
Notice that I am not actually controlling the sorting or the paging itself. I am only forcing the GridView to call upon the main UpdatePanel (upWEF1) to refresh itself via an Update() call. The next step is to grab the ModalPopup I want to keep visible and re-Show() it!
And that's all there is to it!
I am sure there is a cleaner solution using JavaScript itself, but for me this avoids that dread meaningless error and I have a clean set of popups and update panels that can handle both hotlinks, sorting and paging as I want the GridView to perform!
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
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.