Ok so I have an update panel sorrounding my controls. I have 2 dropdownlists which have functions they run from codebehind and a repeater of items. I've done the test in a Repeater using a button it doesn't do a postback, but the linkbutton does. What am I doing wrong?
also this is inside a usercontrol no aspx page.
<asp:UpdatePanel ID="upLocation" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:Repeater ID="rptMuniProducts" runat="server">
<HeaderTemplate>
<table class="table">
<thead>
<tr>
<th class="w80"></th>
<th>Product</th>
<th>Product Type</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="actions">
<asp:Button ID="btnProd" runat="server" OnClick="btnProd_Click" Text="test" />
<asp:LinkButton ID="lnkDeleteProd" runat="server" OnClick="lnkDeleteProd_Click">Link Test</asp:LinkButton>
<asp:HiddenField ID="hdnId" runat="server" Value='<%# DataBinder.Eval(Container, "DataItem.Id") %>' />
</td>
<td><%# DataBinder.Eval(Container, "DataItem.Name") %></td>
<td><%# DataBinder.Eval(Container, "DataItem.Producttype") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Have you tried setting ClientIDMode=Auto on the LinkButton? There's a long-standing .NET bug with doPostBack and non-auto client ids.
Related
I have a listview that I want to update every 5 seconds or so, the update panel does refresh but to no effect.
<asp:Timer runat="server" ID="UP_Timer" Interval="5000" />
<asp:UpdatePanel runat="server" ID="Proc_UpdatePanel">
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server"
DataKeyNames="procName"
ItemType="SerMon.RemoteProcess" SelectMethod="fetchFromQueue">
<EmptyDataTemplate>
<table>
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td />
</EmptyItemTemplate>
<LayoutTemplate>
<table runat="server" id="table1" class="table table-striped table-hover ">
<thead>
<tr runat="server">
<th>#</th>
<th>Process</th>
<th>Status</th>
<th>Machine</th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</thead>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>1</td>
<td>
<asp:Label runat="server" ID="lblId"><%#: Item.ProcName%></asp:Label></td>
<td>
<asp:Label runat="server" ID="Label1"><%#: Item.Procstatus%></asp:Label></td>
<td>
<asp:Label runat="server" ID="Label2"><%#: Item.mcName%></asp:Label></td>
</tr>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
The whole page refreshes, yet the method to be called for populating the listview is not called. Where am I going wrong?
There are 2 different issues here.
First of all the Timer is outside the UpdatePanel, so of course it will do a full PostBack. Move the timer inside the UpdatePanel.
Second, you did not specify an OnTick event for the timer. Without it the Timer will just refresh the page.
<asp:UpdatePanel runat="server" ID="Proc_UpdatePanel">
<ContentTemplate>
<asp:Timer runat="server" ID="UP_Timer" Interval="5000" OnTick="UP_Timer_Tick" />
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
protected void UP_Timer_Tick(object sender, EventArgs e)
{
//update the ListView
}
this is my code to view products as list view inside each item in list view i want to view list of items how can i do this? i can not understand the concept of the eval function and i want to know if i can pass to it list items from code behind without data Bind or it basically depends on data-bind ?
<asp:ListView ID="mylistView" runat="server" GroupItemCount="3">
<EmptyDataTemplate>
<table id="Table2" runat="server">
<tr>
<td>
No data was returned.
</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td id="Td3" runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<table border="0" width="300" style="display: inline-block; background-color: Lime;">
<tr>
<td>
 
</td>
<td>
<a href='ContactUs.aspx'>
<image src='productsImg/<%# Eval("Pic_Path") %>' width="100" height="75" border="0">
</a> 
</td>
<td>
<a><b style="text-decoration: underline;">
<%# Eval("MenuName") %></b> </a>
<br />
want to view here list of items
I
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="groupPlaceholderContainer" runat="server">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
this is code behind...
dataSource.ConnectionString = connetionString;
dataSource.SelectCommand = "SELECT * FROM tbl_WebMenu where MenuID like'3_';";
mylistView.DataSource = dataSource;
mylistView.DataBind();
thanks in advance.
Eval is used to bind to an UI control that is supposedly read only. it can be used to set any type of property of control.
The complete syntax is "Databinder.Eval", it has to be used in conjunction with databind.
Look at this example.
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblRead" runat="server" Text='<%# Eval("FieldName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
you can even set a property of control using eval. it provides flexibility.
But there is a downside of eval as it uses reflection to evaluate the expression.
Read more here http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx#remarksToggle
I have a Listview and one of the columns is called id_Number.
Is it possible to redirect to another page, if user clicks on one of the rows?
For example if id_Number is 4, than page should be redirected to ~/Page.aspx?id=4.
Code:
<asp:ListView ID="ListView1" runat="server"
DataKeyNames="id_Number" >
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="font-family: Arial; color: #FFFFFF" onMouseOver="this.bgColor='#219DD0';" onMouseOut="this.bgColor='#252526';">
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id_Number") %>' />
</td>
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
<td>
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
Name</th>
<th id="Th2" runat="server">
Text</th>
<th id="Th3" runat="server">
Date</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
You can add an HTML link or a JavaScript into the ItemTemplate of your ListView pretty easily:
The "columns" are just HTML columns; in the ItemTemplate, you have access to all of your data, including id_number, so you can use it anywhere in the HTML, not just inside a column.
Since you wan the whole row to be clickable, I'd use a JavaScript function on the onClick event of the HTML table row <TR> element. You already have 2 events (onMouseOver, onMouseOut), with JavaScript in them, so this would just be one more...
A JavaScript redirect utilizes window.location.href which will redirect in the same window, assuming that's what you want (as opposed to a new window, etc.):
<ItemTemplate>
<tr style="font-family: Arial; color: #FFFFFF"
onMouseOver="this.bgColor='#219DD0';"
onMouseOut="this.bgColor='#252526';"
onClick="window.location.href = 'some/path/Page.aspx?id=<%# Eval("id_Number") %>';"
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id_Number") %>' />
</td>
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
<td>
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
One thing to note is for the path of Page.aspx, you have to use a relative path.
~/page.aspx?id=
Is a .net path that gets compiled into the full relative path to that page.
However, bacause your ItemTemplate contains HTML, you'd need the full (relative) path to Page.aspx in there.
So instead it should be (just an example):
/some/path/page.aspx?id= <-- page.aspx lives on http://www.yoursite.com/some/path/page.aspx
/page.aspx?id= <-- page.aspx lives on root, http://www.yoursite.com/page.aspx
Alternately you can use
onClick="window.location.href = '<% System.Web.VirtualPathUtility.ToAbsolute("~/Page.Aspx?ID=" + Eval("id_number")); %>';"
I have browsed the different cases already answered about the topic but did not find the one answering my question:
<asp:ListView ID="lstView_phoneUsersExtensionsFound" runat="server" OnItemDataBound="lstView_phoneUsersExtensionsFound_ItemDataBound">
<LayoutTemplate>
<table id="tbl1" runat="server" class="bordered">
<tr id="tr1" runat="server">
<th id="th1" runat="server" visible='<%# selectOptionVisible %>' >Select</th>
<th id="th1" runat="server">UserID</th>
<th id="th2" runat="server">Firstname</th>
<th id="th3" runat="server">Lastname</th>
</tr>
<tr id="ItemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td runat="server" visible='<%# selectOptionVisible %>' >
<input type="radio" name="rdbutton_userSelection" value='<%# Eval("uuid") %>' />
<asp:HiddenField runat="server" ID="hdfield_userID" Value='<%# Eval("uuid")%>' />
</td>
<td><asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# String.Format("~/Users/DisplayUserDetails.aspx?selectedCCMUserID={0}&uuid={1}",Eval("userID"),Eval("uuid"))%>'><%# Eval("userID")%></asp:HyperLink></td>
<td><%# Eval("firstname")%></td>
<td><%# Eval("lastname")%></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate></EmptyDataTemplate></asp:ListView>
The repeater layouttemplate header does not take into account the visible value but the different items work well and hide the cell when needed.
I would like to keep using an aspx function and not go through javascript or CSS if possible.
Any idea?
Well the below code does the trick but I am sure there should be a better way.
protected void lstView_phoneUsersExtensionsFound_ItemDataBound(object sender, ListViewItemEventArgs e)
{
HtmlTableCell th_selectColumn = (HtmlTableCell)lstView_phoneUsersExtensionsFound.FindControl("th1");
th_selectColumn.Visible = selectOptionVisible;
}
Try this...
<th id="th1" runat="server" visible='<%# Eval("selectOptionVisible") %>'>
The problem was in visible='<%# selectOptionVisible %>'
Instead I changed it to visible='<%# Eval("selectOptionVisible") %>'
Make sure that your data source contains a column as selectOptionVisible
Note
To hide the column header i.e <th>,
Load the "selectOptionVisible to a variable in the code behind while page loading.
Instead of '<%# Eval("selectOptionVisible") %>'
now you can use '<%# selectOptionVisibleVariable %>'.
Set value for selectOptionVisibleVariable before loading data to ListView.
I have a problem getting an <asp:UpdatePanel..> to work inside a <table>.. <tr> </tr> structure and I don't know why. When the UpdatePanel is commented out everything works fine, but when I un-comment the UpdatePanel the contents of the <tr> </tr> tag doesn't even show up in Visual Studio 2010. This content does display when I run the web page but the UpdatePanel doesn't work. Non of my other web pages in this project have this problem but, then again, I use <div>s instead of <table>s in them.
One other thing. The is in my MasterPage.
Here is my script:
<asp:UpdatePanel ID="W9UpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<tr>
<td colspan="6">
<div class="branchSetupSectionTitle">W-9 Information:</div>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnDownloadW9Pdf" runat="server"
Text="Download W-9" onclick="btnDownloadW9Pdf_Click" AutoPostBack="True" />
<%--<asp:RegularExpressionValidator ID="RegularExpressionValidator24"
runat="server" ControlToValidate="txtFirstPaymentAmount" Display="Dynamic"
ErrorMessage="The dollar amount you entered is in the wrong format."
ForeColor="Red" ValidationExpression="^\d+(\.\d\d)?$">*</asp:RegularExpressionValidator>--%>
<asp:CheckBox ID="chkW9FormSubmitted" runat="server" AutoPostBack="True"
oncheckedchanged="chkW9FormSubmitted_CheckedChanged"
Text=" I have submitted this W-9 Form" />
</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
</tr>
The event fires for both the button and the checkbox but the entire page is refreshed.
Thanks for your help.
UpdatePanel needs to render a div or span in order to function correctly. Since neither of these elements can be rendered between table rows, UpdatePanel does not have a placeholder to render the postback response html, and thus it doesn't work.
A workaround in your case may be to see which part of your page does not need to be inside the update panel and leave it outside. You could leave just the contents of <td colspan="2"> inside the UpdatePanel.
<asp:ScriptManager ID="scm" runat="server">
</asp:ScriptManager>
<fieldset>
<legend>Truck Master Entry Form</legend>
<asp:UpdatePanel ID="upd1" runat="server">
<ContentTemplate>
<table cellpadding="2" cellspacing="1">
<tr>
<td align="right">
Truck no :
</td>
<td align="left">
<asp:TextBox ID="truckno" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
Size :
</td>
<td align="left">
<asp:DropDownList ID="drptrucksize" runat="server" Width="120px" Height="20px" DataValueField="WEIGHT"
DataTextField="SIZE" OnSelectedIndexChanged="drptrucksize_SelectedIndexChanged"
AutoPostBack="true" />
</td>
</tr>
<tr>
<td align="right">
Type :
</td>
<td align="left">
<asp:TextBox ID="txttrucktype" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
Weight :
</td>
<td align="left">
<asp:TextBox ID="txtweight" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
</td>
<td align="left">
<asp:Button ID="btnsave" runat="server" Text="Save" Width="100px" Height="50px" />
<asp:Button ID="btncancel" runat="server" Text="Cancel" Width="100px" Height="50px" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
The update panel need to be put outside the table. Look at
Mohammad Shahnawaz's code.