gridview not visible in updatepanel in ASP.NET - c#

I currently have a GridView in a pop-up control. The GridView is embedded in an UpdatePanel and I have the window pop-up showing nothing on it. However, when I debug through it I see that the GridView has data in it and it is bound, but I am not noticing any changes. I even tried to call the Update method on the UpdatePanel, but received no changes in that either.
Basically what I wish to do is show a blank page up until my data has been loaded in. After the GridView has the data bound to it I would like it to be visible. Please find the below code snippet of the current process.
ASPX source:
<dx:ASPxPopupControl ID="ASPxPopupItem" runat="server" ClientIDMode="AutoID" LoadingPanelImagePosition="Bottom"
Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
EnableAnimation="False" HeaderText="Item Checker"
Width="614px">
<ContentCollection>
<dx:PopupControlContentControl ID="PopupCoverageItem" runat="server" SupportsDisabledAttribute="True">
<table style="width: 611px" cellpadding="3" cellspacing="3">
<tr>
<td align="center">
Title
</td>
</tr>
<tr>
<td colspan="2">
<div style="height: 75px; overflow: auto; width: 595px;">
<asp:UpdatePanel runat="server" ID="udpItems" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView runat="server" ID="gvTitles" Width="575px" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="90px">
<ItemTemplate>
<center>
<asp:ImageButton OnClick="btnSelect_Click" ID="lnk_Select" runat="server" CommandArgument='<%# Eval("title") %>'
ImageUrl="~/images/save.png" ToolTip="Choose this record" />
</center>
</ItemTemplate>
<HeaderStyle Width="90px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField HeaderText="Item ID" DataField="item_id" SortExpression="item_id" />
<asp:BoundField HeaderText="Title" DataField="title" SortExpression="title" />
<asp:BoundField HeaderText="Date" DataField="date" SortExpression="date" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</td>
</tr>
<tr>
<td align="center">
<asp:Button runat="server" ID="btnCancelTitle" Text="Cancel" CssClass="popupButton"
OnClick="btnCancelTitle_Click" />
</td>
</tr>
</table>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
C# back end:
// Bind the data from the returning SQL query and update
gv.DataSource = npgDat;
gv.DataBind();
udpItems.Update();
Unfortunately there isn't much more of the C# back-end that I can show since we're using a company specific Query tool that works well in other situations.
Thanks

Are you sure an ASPxPopupControl supports having an UpdatePanel as content? I'd try getting rid of the UpdatePanel and see if the GridView works as expected then, or try moving the UpdatePanel (with the GridView still inside it) outside of the ASPxPopupControl and see if that works. If the problem is having the UpdatePanel inside the ASPxPopupControl, then you'll probably have to contact DevExpress for more help, as that would lead me to believe it's a problem with their control.
Update
Based on your comment below, you may want to look into Example: How to show the ASPxLoadingPanel while the content is loading inside the ASPxPopupControl over on the DevExpress support forum.

Related

Asp image button click event not firing for all row when it is inside a update panel which is inside a grid view

I am facing a strange problem. Inside a grid view I have some image button which is again inside update panel to load some calendar content with partial post back without any page refresh.
This partial postback is working for first few rows but after few rows, lets say around 15 rows the button click event not hitting and only breakpoint going in page load event and the the entire page refresh.
there are huge data in each row but I am for example showing the update panel structure. please help me to fix the issue . I have tried various way to fix it but still facing same issue.
<asp:GridView ID="GVSales" runat="server" AllowPaging="false" AutoGenerateColumns="false" DataKeyNames="UserId" BackColor="#FFFFCC" EmptyDataText="No salesman selected to show" OnRowDataBound="GVSales_OnRowDataBound" OnDataBound="GVSales_AfterDataBound">
<PagerSettings Visible="false" />
<AlternatingRowStyle BackColor="#99CCFF" />
<Columns>
<asp:BoundField DataField="GroupName" Visible="false" />
<asp:TemplateField>
<ItemTemplate>
<table width="100%" border="1px" cellpadding="0" cellspacing="0" style="color: Black; font-family: Arial; text-align: center">
<tr>
<td colspan="18" style="text-align: left">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
<div id="divNavigateCal" runat="server" style="float: right; display: none">
<asp:HiddenField ID="hdnDaydiff" runat="server" Value="1" />
<div class="blink" id="BlinkLoad" style="width: 100px; padding-top: 10px; vertical-align: top; display: none">Please Wait...</div>
<asp:ImageButton ID="imgBtnPrevious" AutoPostback="false" runat="server" class="Previous" CommandArgument='<%# Eval("UserId")%>' Customid='<%# Eval("UserId") %>' OnClientClick='<%# "GetCustomerID(" + Eval("UserId") + ");" %>' ImageUrl="~/admin/images/cal_previous.gif" OnClick="imgBtnPrevious_Click" />
<asp:ImageButton ID="imgBtnNext" runat="server" class="Next" CommandArgument='<%# Eval("UserId")%>' Customid='<%# Eval("UserId") %>' OnClientClick='<%# "GetCustomerID(" + Eval("UserId") + ");" %>' ImageUrl="~/admin/images/cal_next.gif" OnClick="imgBtnNext_Click"/>
</div>
<input type="button" class="ShowCalendar" value="Show/Hide Calendar" runat="server" data-id='<%# Eval("UserId")%>' /> <asp:Label ID="lbl_alert1" runat="server" Text="Started this week with low meetings" ForeColor="Red" Font-Bold="true" Width="300" Visible='<%# (Convert.ToBoolean(Eval("Alert1"))) %>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Did not create 7 meetings on monday." ForeColor="Red" Font-Bold="true" Width="300" Visible='<%# (Convert.ToBoolean(Eval("Alert2"))) %>'></asp:Label>
<table id="calendar">
<tr>
<td>
</td>
</tr>
</table>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgBtnPrevious" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="imgBtnNext" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here I am updating the table calendar content with partial postback for button click event of imgBtnPrevious imgBtnNext which has some calendar like structure.
This code is working fine for 1st 14 - 15 rows but this issue coming after that.
Note:
there are other huge data in each row but here i have shown only the update panel structure for example.
UPDATE
I have investigated the issue further and disabled all update panels to check if update panel is causing issue but I found it not due update panel. The buttons click event is not firing after 14 -15 rows. even tried with row command and still same. what may be the root of this issue? any solution? please help. Whenever i click the button it just reload the page but click event is not hitting the debugger.
I found the issue. OnRowdataBound of grid view there was some code which was appending extra row in that table which was causing this strange issue.

aspx Updatepanel not updating - contains Gridview

I am trying to write some data to a database and then update the gridview with the updated data. There is a nested gridview inside the other. I also have two update panels. The child gridview is inside parent updatepanel. at the end of parent updatepanel, child update panel starts, that has a button.
On click I have managed to write to the DB, using find control, I can find the dynamic gridview, re-bind it to the data source. I can also find the child updatepanel and I am using the update method. but it is not updating. I am getting no errors.
<ItemTemplate>
<img alt="" runat="server" style="cursor: pointer" src="images/plus.png" />
<asp:UpdatePanel ID="pnlOrders" runat="server" Style="display: none" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="OrderId" HeaderText="Contact Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="OrderDate" HeaderText="City" />
</Columns>
</asp:GridView>
<asp:UpdatePanel id="pnChild" runat="server" CssClass="ChildGrid" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("CustomerID") %>'></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="MyButtonClick" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
C Sharp code:
GridView gvOrder = gvr.FindControl("gvOrders") as GridView;
gvOrder.DataSource = GetData(string.Format("select top 10 * from Orders where CustomerId='{0}'", cID));
gvOrder.DataBind();
UpdatePanel uPanel = gvr.FindControl("pnlOrders") as UpdatePanel;
uPanel.Update();
Html output:
<table class="Grid" cellspacing="0" rules="all" border="1" id="gvCustomers" style="border-collapse:collapse;">
<tr>
<th scope="col"> </th><th scope="col">Contact Name</th><th scope="col">Contact Name</th><th scope="col">City</th>
</tr><tr>
<td>
<img src="images/plus.png" alt="" style="cursor: pointer" />
<div id="gvCustomers_pnlOrders_0">
<div>
<table class="ChildGrid" cellspacing="0" rules="all" border="1" id="gvCustomers_gvOrders_0" style="border-collapse:collapse;">
<tr>
<th scope="col">Contact Name</th><th scope="col">City</th>
</tr><tr>
<td style="width:150px;">1</td><td style="width:150px;">19-05-18</td>
</tr><tr>
<td style="width:150px;">12</td><td style="width:150px;">25-05-18</td>
</tr>
</table>
</div>
<div id="gvCustomers_pnChild_0" CssClass="ChildGrid">
<input name="gvCustomers$ctl02$TextBox1" type="text" id="gvCustomers_TextBox1_0" />
<input name="gvCustomers$ctl02$TextBox2" type="text" value="1" id="gvCustomers_TextBox2_0" />
<input type="submit" name="gvCustomers$ctl02$Button1" value="Button" id="gvCustomers_Button1_0" />
</div>
The HTML layout looks wrong, but that's because I have only posted output of one row. There are no layout issues.
When you use the UpdateMode="Conditional" then you have to set the ChildrenAsTriggers="False".
And manually trigger your button(s) or other controls events as AsyncPostBackTrigger like:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
and manually update your updatepanel as yourupdatepanel.Update():
UpdatePanel uPanel = gvr.FindControl("pnlOrders") as UpdatePanel;
uPanel.Update();
The issue seemed to be with nesting of the panels. I changed the child updatepanel to just a panel and all seems to be working without needing a trigger declaration.

Capture Value From Hidden ItemTemplate Field

I have a gridview and I need to capture the value of my label, but have it not be displayed. ANytime I set it to hidden I am no longer able to capture the value. What should I alter so the label is hidden, but I still am able to capture the value? eghead is what I am wanting to hide but still capture the value of
<td valign="top" style="text-align: left; width: 200px;">
<asp:GridView runat="server" ID="gridview1" AutoGenerateColumns="false" GridLines="Both" ShowFooter="true" >
<Columns>
<asp:BoundField DataField="rdf" HeaderText="redfern" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("egh") %>' ID="eghead" ></asp:Label>
<asp:CheckBox ID="Sans" runat="server" AutoPostBack="false" Checked='<%# Convert.ToBoolean(Eval("Remember")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
use the
style="display:none"
in the control. This way it will not be displayed in the UI but it will be available in the client side for manipulation.
Another alternative is to set a property of your checkbox and then use it using jquery or using javascript method. The asp.net renders the custom property as it is on client side.

Is this a FormView bug?

I have a FormView (with paging enabled) that is bound to a LinqDataSource on an ASP.NET page. I'm experiencing some very weird behavior and can't figure out why it's happening. For simplicity sake on this question I have removed some unneeded code (other FormView templates, etc) to demonstrate this behavior.
My FormView has 3 fields, two textboxes and one DropDownList. The DropDownList is bound to another LinqDataSource on the page and contains foreign key values. When the FormView's LinqDataSource only contains one record and I try to update it, the update fails because the selected value of the DropDownList is always empty, no matter which value I pick for it. When the FormView's LinqDataSource contains 2 or more records, it works as it should.
Now here's the really weird thing. The update is actually failing because of the FormView's PagerSettings! When I use just the default Pager settings, all is well. When I change the PagerMode to NextPreviousFirstLast, the update fails.
Here's my FormView with it's data sources:
<asp:FormView ID="fvData" runat="server" AllowPaging="True"
DataKeyNames="ID" DataSourceID="ldsData" DefaultMode="Edit">
<EditItemTemplate>
<table class="pad5">
<tr>
<td class="field-name">AREA:</td>
<td>
<asp:DropDownList ID="cboAREA" runat="server" DataTextField="AREA_NAME"
DataValueField="AREA1" SelectedValue='<%# Bind("AREA") %>' DataSourceID="ldsAreas" />
</td>
</tr>
<tr>
<td class="field-name">LOOP:</td>
<td><asp:TextBox ID="txtLOOP" runat="server" Text='<%# Bind("LOOP") %>' /></td>
</tr>
<tr>
<td class="field-name">LOOP DESCRIPTION:</td>
<td><asp:TextBox ID="txtLOOP_DESCRIPTION" runat="server"
Text='<%# Bind("LOOP_DESCRIPTION") %>' style="width: 600px" /></td>
</tr>
</table>
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CausesValidation="True" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="False" />
</EditItemTemplate>
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="&lt;&lt; First" LastPageText="Last &gt;&gt;"
NextPageText="Next &gt;" PreviousPageText="&lt; Prev"
Position="TopAndBottom" />
<PagerStyle CssClass="pager" />
</asp:FormView>
<asp:LinqDataSource ID="ldsData" runat="server"
ContextTypeName="E_and_I.EAndIDataDataContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" EntityTypeName=""
TableName="INSTRUMENT_LOOP_DESCRIPTIONs" onselecting="ldsData_Selecting" OrderBy="ID ASC" >
</asp:LinqDataSource>
<asp:LinqDataSource ID="ldsAreas" runat="server"
ContextTypeName="E_and_I.EAndIDataDataContext" EntityTypeName=""
TableName="AREAs" onselecting="ldsAreas_Selecting">
</asp:LinqDataSource>
And here's both of my LinqDataSource's Selecting events:
EAndIDataDataContext db = new EAndIDataDataContext();
protected void ldsData_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = db.INSTRUMENT_LOOP_DESCRIPTIONs.Take(1); // we only want one record for testing
}
protected void ldsAreas_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = db.AREAs.OrderBy(a => a.AREA1).Select(a => new { AREA1 = a.AREA1, AREA_NAME = "(" + a.AREA1 + ") " + a.AREA_NAME });
}
I've traced the problem to these lines:
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="&lt;&lt; First" LastPageText="Last &gt;&gt;"
NextPageText="Next &gt;" PreviousPageText="&lt; Prev"
Position="TopAndBottom" />
As soon as I remove the above PagerSettings element, the FormView updates the record just fine! Does anybody know why the hell the pager settings would have anything to do with this? I'm using the .NET Framework 4.0.
I copied part of your code and I made an experiment and I think, I'm experimenting the same behavior.
This is what I did:
<asp:LinqDataSource runat="server" ID="lds"
TableName="jobs" ContextTypeName="WebApplication2.DataAccess.PubsDataContext" >
</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="ldse"
TableName="employee" ContextTypeName="WebApplication2.DataAccess.PubsDataContext" OnSelecting="ldse_Selecting">
</asp:LinqDataSource>
<asp:FormView runat="server" DefaultMode="Edit" ClientIDMode="Predictable" DataKeyNames="emp_id" DataSourceID="ldse"
AllowPaging="true" OnItemCommand="Unnamed_ItemCommand" ID="formView">
<EditItemTemplate>
<div>
<asp:DropDownList runat="server" ID="ddlJobs" DataSourceID="lds" DataTextField="job_desc" DataValueField="job_id">
</asp:DropDownList>
</div>
<div>
<asp:TextBox runat="server" TextMode="MultiLine" ID="txtDesc" />
</div>
<div>
<asp:Button Text="Save" runat="server" CommandName="Save" CausesValidation="true" />
<asp:Button Text="Cancel" runat="server" CommandName="Cancel" CausesValidation="false" />
</div>
</EditItemTemplate>
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="&lt;&lt; First" LastPageText="Last &gt;&gt;"
NextPageText="Next &gt;" PreviousPageText="&lt; Prev"
Position="TopAndBottom" />
These are my observations:
If the FormView contains only one row, then the FormView behaves weird and my commands do not work as expected.
My Save command is never fired, instead the `Cancel command is fired
My Cancel command causes my FormView to disappear...
First I thought this was because of the & characters, but this is not the case
I narrowed the problem to Position="TopAndBottom"
If you set the Position attribute to:
Top
TopAndBottom
You will experiment the same problem. (As you mention probably a bug)
If you set the Position attribute to:
Buttom
It works as expected
To be honest, if this is a bug, I can't believe none else has found it and report it.
I made the same experiment with Visual Studio 2012 for Web (ASP.NET 4.5) and I'm experimenting the exact same behavior...
This makes me think that probably I'm doing something fundamentally wrong and perhaps this is not a bug and that's why I'm experimenting the same behavior with both versions ASP.NET 4 and ASP.NET 4.5, but if that's the case, I simply can't figure out what is it.
On the other hand, if this is a bug, the same bug will be present in ASP.NET 4.5
Edit 1
I uploaded the code to my GitHub site for reference
It's most likely due to the url decoding of the &amp &lt and &gt.
Try taking out the &amp';' and just use the & symbol. You are able to inject using that method.

button in gridview triggers all validators when it should not

Let me start off by saying I know how to use CausesValidation and ValidationGroup. I have bizarre situation where I have an Ajax Tab container. Each tab has a gridview and the rows that generate in the gridviews all have a TemplateField containing an 'Add' button. The buttons in the gridview and tab containers all use ValidationGroup to prevent any cross contamination and all the 'Add' buttons are set to CausesValidation = "false"
I just added the last gridview and the 'Add' button triggers all validators on the page. Once more the 'Add' button is set as CausesValidation = "false" so there is NO reason for it to behave in this fashion. I even set this value on the front end AND in the code behind.
For attempts I have tried the suggestions in these links: "Solution 1" and "Solution 2"
Has anyone else come across this and found a solution?
Edit Request for code:
I will post only the Tab Panel in question as the whole container is almost 500 lines
<asp:TabPanel ID="tab_Browse" runat="server" HeaderText="Browse">
<ContentTemplate>
<table id="browseTable">
<tr>
<td>Category</td>
<td>
<asp:DropDownList ID="browseDDL" runat="server" AppendDataBoundItems="True">
<asp:ListItem Text="All categories" Value="999"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button ID="btnBrowse" runat="server" Text="Browse" ValidationGroup="vgBrowse" OnClick="btnBrowse_Click" />
</td>
</tr>
</table>
<asp:GridView ID="gvBrowse" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="8"
OnPageIndexChanging="gvBrowse_PageIndexChanging" DataKeyNames="foodId"
OnRowDataBound="gvBrowse_RowDataBound" Width="790px">
<Columns>
<asp:TemplateField HeaderText="Food ID" Visible="false">
<ItemTemplate>
<%# Eval("foodId") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<%# Eval("Shrt_Desc") %> (100g)
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Calories" ItemStyle-Width="50px">
<ItemTemplate>
<%# Eval("cals") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fat Grams" ItemStyle-Width="75px">
<ItemTemplate>
<%# Eval("fat") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Carbs" ItemStyle-Width="50px">
<ItemTemplate>
<%# Eval("carbs") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="110px">
<ItemTemplate>
<asp:Button ID="browseAdd" runat="server" CausesValidation="false" Text="Add to meal" CommandArgument="Standard" OnClick="showingEntry" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="gvRowStyle" />
<HeaderStyle CssClass="gvHeader" />
<AlternatingRowStyle CssClass="altRow" />
</asp:GridView>
</ContentTemplate>
</asp:TabPanel>
Edit 2 Another interesting tidbit. If I put OnClientClick="alert(Page_IsValid)" on my add button it returns true even though the validators in the others tabs are triggered. if i click the button a second time it returns false and my codebehind fails as if the page posted back but skipped the OnDataBound method
I ended up resolving this problem by preloading the gridview with an empty row. Makes no sense as to why this resolved the problem, but it does.

Categories

Resources