<asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" />
<asp:UpdatePanel runat="server" id="pnlUpdate">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" eventname="Tick"/>
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="table table-hover table-condensed"
GridLines="None" AllowPaging="true" PageSize="20"
OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField ItemStyle-Width="50%" DataField="Story" HeaderText="Story"/>
<asp:BoundField ItemStyle-Width="15%" ItemStyle-Wrap="false" DataField="AssignedTo" HeaderText="Assigned To"/>
<asp:BoundField ItemStyle-Width="15%" ItemStyle-Wrap="false" DataField="Status" HeaderText="Status"/>
<asp:BoundField ItemStyle-Width="15%" ItemStyle-Wrap="false" DataField="Started" HeaderText="Started"/>
<asp:BoundField ItemStyle-Width="5%" ItemStyle-Wrap="false" DataField="Updated" HeaderText="Updated"/>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Buttonid" runat="server" CommandName="ViewItem" Text="View" BorderStyle="None" BackColor="White"
OnClick="Button_click_event"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="cursor-pointer" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Button_click_event won't fire when I have update panel, but it works when it is not in the update panel.
your update panel look like
<asp:UpdatePanel ID="upWall" runat="server" ChildrenAsTriggers="true" UpdateMode="conditional">
<ContentTemplate>
....
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Buttonid" EventName="Click"/>
</Triggers>
Try setting UpdateMode="Conditional" and ChildrenAsTriggers="False" to the UpdatePanel..
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" />
</Triggers>
Also remove the EventName attribute for your trigger and try again..
Remove the attribute of button click CommandName="ViewItem"
and then try , if not work also add Property of button UseSubmitBehaviour=true
You could solve this in various ways. One way is on rowdatabound in the code behind adding a control that can handle an onclick event, for example a div, and then add a postback handler to your clickable control:
HtmlGenericControl div = (HtmlGenericControl)e.Row.FindControl("Buttonid");
div.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));
Alternatively, I implemented another workaround that works for me:
place a button outside your gridview, but inside the Updatepanel. Also, add a hiddencontrol, where you are going to store the rowindex clicked. Then Add to your template field a 'clickable div' (in which you can put a label for your text), that calls a javascript. Something like this (you can add a display none style to hide the button).:
<asp:Button id="Buttonid" runat="server" OnClick="Button_click_event" />
<asp:HiddenField ID="hdnRowClicked" runat="server" Value="" />
<itemtemplate>
<div onclick="javascript:rowClicked('<%= Buttonid.ClientID %>','<%= hdnRowClicked.ClientID %>', this);">
<asp:Label ID="lblImgDetail" runat="server" Text="+"></asp:Label>
</div>
</itemtemplate>
Then within the javascript function, set the rowindex and call the button to do the postback:
function rowClicked(btnId, hdnRowSelected, lnk) {
var rowIndex = lnk.parentNode.parentNode.rowIndex - 1;
$('#' + hdnRowSelected).val(rowIndex);
$('#' + btnId).click();
}
Related
Ok , this is running me nuts. I have tried any possible solution and it is not working.
Here is the problem:
I have a gridview in my parent page. Each row has an "Edit" button which opens a new page:
<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="" Text="Edit" OnClientClick='<%# Eval("ID", "window.open(\"EditFrm.aspx?ID={0}\", null, \"width=700,height=600,top=100,left=300\", \"true\");") %> '/>
in Child page, I populate all the fields from db and with clicking on "update" save all the data into dab and close the current page:
<script>
function RefreshParent() {
window.opener.document.getElementById('Button1').click();
window.close();
}
</script>
Button1 includes a method to refresh Gridview data from db.
I have tried following code but it doesn't refresh the gridview:
window.opener.location.reload(true);
Here is the definition of gridview in my parent window:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="" Text="Edit" OnClientClick='<%# Eval("ID", "window.open(\"EditFrm.aspx?ID={0}\", null, \"width=700,height=600,top=100,left=300\", \"true\");") %> '/>
</ItemTemplate>
</asp:TemplateField>
// Column definition
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" />
</Triggers>
</asp:UpdatePanel>
Any support is appreciated.
This was really interesting.
I solved the problem with following code. This prevents javascript function to run before C# update.
<asp:placeholder id="refresh_script" visible="false" runat="server">
<script>
window.opener.location.reload();
window.close();
</script>
</asp:placeholder>
Then you need to add this to your code behind in .cs
refresh_script.Visible = true;
I am having an issue getting the popup to appear at all. Once I can get the popup to show at all, I can troubleshoot from there. Basically, I have a gridview and I want a detailsview to appear in a popup when I select a link. This is all being done using an objectdatasource.
Note:The grid and the detailsview work just fine if I don't try to use a modalpopupextender.
My question is whether anyone can tell me what I am doing wrong in my code, or offer a better solution for implementing the ajax modalpopupextender.
~This is a shortened version of my markup~
<asp:Content ID="Content2" ContentPlaceHolderID="MasterContentPlaceHolder" Runat="Server">
<asp:ScriptManager ID="script1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataSourceID="ObjectDataSource1" AllowSorting="True"
CssClass="grid" CaptionAlign="Left" DataKeyNames="APP,ENV" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
>
<Columns>
<asp:TemplateField ShowHeader="False" Visible = "false">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Select" Text="Select" Visible ="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="APP" SortExpression="APP">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Visible = "false" Text='<%# Bind("APP") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="Label1" runat="server" CausesValidation ="false" CommandName="Select" Text='<%# Bind("APP") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ENV" HeaderText="ENV"
SortExpression="ENV" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlPopup" runat="server" Width= "700px" style="display:none;">
<asp:UpdatePanel ID="detailspanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server"
TargetControlID="btnShowPopup" PopupControlID="pnlPopup"
/>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="ObjectDataSource2" CssClass="detail"
>
<Fields>
<asp:BoundField DataField="APP" HeaderText="APP"
SortExpression="APP" />
<asp:BoundField DataField="ENV" HeaderText="ENV"
SortExpression="ENV" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Select" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetApplication"
TypeName="Applications.BusinessServices.AppService"
DataObjectTypeName="Applications.Entities.Application"
UpdateMethod="Update">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="APP"
PropertyName="SelectedDataKey[0]" Type="String" DefaultValue="Null" />
<asp:ControlParameter ControlID="GridView1" Name="ENV"
PropertyName="SelectedDataKey[1]" Type="String" DefaultValue=" Null" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllApplication"
TypeName="Applications.BusinessServices.AppAvailService" SortParameterName="sortColumn">
</asp:ObjectDataSource>
</asp:Content>
To sum it up, when the linkbutton label1 is clicked, the modalpopup should appear and show the detailsview.
~This is my codebehind~
protected void Page_Load(object sender, EventArgs e)
{
if (GridView1.SelectedIndex == -1)
{
GridView1.EnablePersistedSelection = true;
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DetailsView1.Visible = true;
this.DetailsView1.DataBind();
this.detailspanel.Update();
this.mdlPopup.Show();
}
}
I have confirmed via debugging that that mdlPopup.Show() does execute when the link is clicked, and visual studio does not register any errors. It is simply that nothing happens.
Also, Btnshowpopup is just a fake button. The popup should still show if I call mdlpopup.show(); from codebehind. Even if set the panel and btnshowpopupp to visible and then click the button, nothing still happens.
Any help would be appreciated. Thanks.
I've resolved my issue. I figured that I would share it for anyone that has a similar issue.
I've seen 12 examples on various sites that show this not to be an issue, but I took the modalpopupextender outside of the updatepanel and the issue was resolved. So at least for me, the modalpopupextender has to be outside of the updatepanel in order for it to fire.
I want the OnRowCommand event of the GridView to not perform a full postback on a ErrorLinkButton click. So I wrapped the control in an update panel and added an AsyncPostBackTrigger for OnRowCommand:
<asp:GridView ID="DataSourceMappingGridView" runat="server" DataKeyNames="Index" ClientIDMode="Static" OnRowCommand="DataSourceMappingGridView_RowCommand" OnRowDataBound="DataSourceMappingGridView_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:UpdatePanel ID="ErrorUpdatePanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataSourceMappingGridView" EventName="OnRowCommand" />
</Triggers>
<ContentTemplate>
<asp:LinkButton ID="ErrorTextLinkButton" CommandName="Errors" CommandArgument='<%#Bind("Index") %>' runat="server" Text='View Errors' />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
But I get the following error:
Could not find an event named 'OnRowCommand' on associated control
'DataSourceMappingGridView' for the trigger in UpdatePanel
'ErrorUpdatePanel'.
The event is called RowCommand not OnRowCommand
Replace
EventName="OnRowCommand"
with
EventName="RowCommand"
and it should work
I have an Updatepanel and Gridview inside it.
<asp:UpdatePanel ID="uplPanel" UpdateMode="Conditional" runat="server" OnLoad="uplPanel_Load">
<ContentTemplate>
<asp:GridView ID="gvPrList" runat="server" AutoGenerateColumns="false" AllowPaging="false"
AllowSorting="false" CssClass="list-table" HeaderStyle-CssClass="header">
<Columns>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="button save" OnCommand="onPrItemCmd"
CommandName="editRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="button save" OnCommand="onPrItemCmd"
CommandName="deleteRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
When I click on my buttons inside the Griview, it does not fire the events.
Any idea?
You need to add OnCommand event of GridView and then handle that inside that event like this:
OnRowCommand="gvPrList_OnRowCommand"
or alternatively add a click event for the individual button and then handle in the code behind file:
<asp:Button ID="btnEdit" runat="server" OnClick="btnEdit_Click" Text="Edit" CssClass="button save"
OnCommand="onPrItemCmd" CommandName="editRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" />
I had the same issue where column buttons with a OnClick were causing a postback but the OnClick method was not being hit. When I commented out the update panel and it all worked.
I resolved this issue by adding a postback trigger for the grid within the update panel:
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="uxWebDataGrid" />
</Triggers>
</asp:UpdatePanel>
Hope this helps someone else!
I did the following and it works
I replace asp button with html button and call javascript method to fire Update Panal Load event.
<input id="btnDelete1" type="button" onclick="javascript:DeletePrItem('<%# Eval("ID") %>');" value="Delete" class="button save" style="width: 80px" />
My Js :
function DeletePrItem(_Id) {
__doPostBack('<%= uplPanel.ClientID %>', _Id);
}
My Code behind :
protected void uplPanel_Load(object sender, EventArgs e)
{
var arg = Request.Params.Get("__EVENTARGUMENT");
if (arg != null)
{
if (arg != "")
{
string recordId = arg.ToString();
//Do deletetion and rebind data grid
}
}
}
This would be the Event Handler for your command in the codebehind:
protected void onPrItemCmd(object sender, CommandEventArgs e)
{
//do whatever you want
//probably you will need the "ID" or "CommandArgument":
string myArgumentID = e.CommandArgument.ToString();
uplPanel.Update(); //since the UpdatePanel is set *UpdateMode="Conditional"*
}
UPDATE:
Probably, you might be doing some validation when you click on buttons. If so, you need to add CausesValidation="false" in your buttons or links properties
I had a similar issue.
Depending on your situation, as in mine...All of the clickable controls inside of the update panel I will want to be triggers; So i was simply able to use the UpdatePanel property 'ChildrenAsTriggers="true"' so solve the issue.
<asp:UpdatePanel runat="server" ID="UPCommunicationlogForm" ChildrenAsTriggers="true" >
This solved my issue, now my edit and delete buttons that are generated from the ItemTemplate inside my gridview call their respective methods on the server.
Please add this code into the UpdatePanel.
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="gvPrList" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I added an OnRowCommand Event and add this trigger to the UpdatePanel:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvPrList" EventName="RowCommand" />
</Triggers>
Note that it's an Async trigger.
This helped me.
In my case I was changing a value in a asp:DropDownList control and then going back to the server to update my asp:GridView which is in a different asp:UpdatePanel. I just forgot to add code to refresh the Update Panel with the list. Once I did that everything worked fine.
Server side
System.Data.DataSet ds = MySQL.DAL.GetRecord(sql);
GV_View.DataSource = ds;
GV_View.DataBind();
UP_MainList.Update(); //refresh the update panel
Aspx code
<asp:UpdatePanel runat="server" ID="UP_ListChange" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddFilter" DataTextField="Desc" AutoPostBack="true" DataValueField="Detail" OnSelectedIndexChanged="GV_CodeView_RefreshScreen" ></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<div class="medium">Select Filter to view database codes</div>
</div>
<div class="div-row-header" runat="server" id="divList">
<asp:UpdatePanel runat="server" ID="UP_MainList" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GV_View" runat="server" AllowSorting="True" AutoGenerateColumns="false" DataKeyNames="id">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" Visible="false" />
<asp:BoundField DataField="Type_Cd" HeaderText="Code" />
<asp:BoundField DataField="Short_Desc" HeaderText=" Description" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="Code_Edit" runat="server" Text="Edit" onClick="GV_Code_Edit_Click" class="button" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</ContentTemplate>
</asp:UpdatePanel>
</div>
IGNORE THIS:
I was rebinding the grid in the Onload method.
I have a grid view with some textboxes, which I have to wrap in a UpdatePanel Control. So it looks like this:
<asp:UpdatePanel ID="upDistribution" runat="server" OnLoad="upDistribution_OnLoad">
<ContentTemplate>
<asp:GridView ID="gvDistributions" runat="server" AutoGenerateColumns="false"
OnRowDataBound="gvDistributions_RowDataBound"
CssClass="TallCells ContrastTable MaxWidth LeftHeaders"
GridLines="Both" ShowFooter="True" style="">
<RowStyle HorizontalAlign="Left" />
<EmptyDataTemplate>
No pricing history data found.
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="PriceA">
<ItemTemplate>
<asp:TextBox ID="txtPriceA" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DistPrice">
<ItemTemplate>
<asp:TextBox ID="txtDistPrice" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
There is a button "Save" when I would like to get the value entered for the txtboxes. If there is no UpdatePanel around the GV, i can can easily get the txtbox values like:
((TextBox)gvDistributions.Rows[0].Cells[0].FindControl("txtPriceA")).Text
But when, the GridView is wrapped with UpdatePanel, the above statement returns the value that was set on the page load.
How can I get the value of the text box without getting rid of the updatePanel. I need the update panel, because the number of rows, and dates are dependent on another variable in another user control.
As per my understanding, you should use a trigger for the update panel which is something like below.
<asp:UpdatePanel ...>
<ContentTemplate>
...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Hope this helps!!
Use your TextBoxes with their AutoPostBack property set True
<asp:TextBox ID="txtPriceA" runat="server" AutoPostBack="True"/>
I was rebinding gridview in the onLoadMethod