Here's the top end of my list view
<asp:ListView ID="ui_lvJobList" runat="server" OnPagePropertiesChanging="ui_lvJobList_PagePropertiesChanging"
OnItemDataBound="ui_lvJobList_ItemDataBound" OnItemCommand="ui_lvJobList_ItemCommand"
OnDataBound="ui_lvJobList_DataBound" OnPagePropertiesChanged="ui_lvJobList_PagePropertiesChanged">
<LayoutTemplate>
<div>
<table class="jobs-table jobs-table-body">
<tbody>
<tr runat="server" id="itemPlaceholder" />
</tbody>
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr id="ui_jobId<%# DataBinder.Eval(Container.DataItem,"JobID") %>" class="<%# DataBinder.Eval(Container.DataItem, "StatusID").ToString() == "1" ? "jobs-row" : "jobs-row-started"%>"
onmouseover="this.style.backgroundColor='#b8e4f7';" onmouseout="this.style.backgroundColor='#efefef';">
<td class="jobs-table-JobId">
<span class="no-decoration cursor-pointer">
<%# DataBinder.Eval(Container.DataItem,"JobID") %>
</span>
</td>
<td class="hidden-ui-control click-me-to-edit">
<asp:LinkButton runat="server" CommandName="EditJob" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"JobID") %>'
ID="ui_btnListViewEditJob" CssClass="no-decoration cursor-pointer">
<%# DataBinder.Eval(Container.DataItem,"JobID") %>
</asp:LinkButton>
</td>
...and here's my jQuery to handle double-click on any cell
$("tr[class^='jobs-row'] td").dblclick(function (e) {
e.preventDefault();
$(this).parent().find("td.click-me-to-edit a").click();
});
... I'm using jquery-1.8.3
The problem: the OnItemCommand is not firing when I double-click the row; there are more cells than I've included but I left them out for brevity.
I've tried with & without the preventDefault.
The dblclick function is being hit, I've run it with the chrome dev tools.
Thanks in advance for having a look. Let me know if I've not included enough of anything.
N
Cracked It!
I changed the LinkButton for a Button (& made the appropriate change to the jQuery selector) & it works OK, now.
Related
I have bound a DataSet to a ListView. In the ListView ItemTemplate, if a row value is empty, I do not want it, or the <td> element it is enclosed in to display.
In my code, the first row value will display. However, when I try to use the If statement on the second <td> element, that will not display.
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"> </asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"> </asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<%# Eval("textItem1") %>
</td>
<% if (!String.IsNullOrEmpty(textItem2){ %>
<td>
<%# Eval("textItem2") %>
</td>
<%} %>
</ItemTemplate>
</asp:ListView>
That If statement works in an aspx page if its NOT being used in a ListView, Repeater, or GridView (or does it?). I need to be able to check if that string row value is empty and not display it or the <td> element it is enclosed in. I am not against a solution that uses code-behind. Is there another way to do this then my attempt?
I used a pretty simple method solution..
In the above code, I swapped out this...
<% if (!String.IsNullOrEmpty(textItem2){ %>
<td>
<%# Eval("textItem2") %>
</td>
<%} %>
For this...
<%# writeText(Eval("textItem2").ToString())%>
And placed this method in the code behind...
public string writeText(string kiss)
{
if (!String.IsNullOrEmpty(kiss))
return "<td> " + kiss + "</td>";
else
return null;
}
I have a page that I am working on that I'm linking multiple user controls to. The user control contains 3 buttons, an attach, clear and view button. When a user clicks on any control on the page, the resulting information is "dumped" into the last visible control on the page.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" MasterPageFile="DefaultPage.master" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%# Register tagName="FileHandler" src="FileHandling.ascx" tagPrefix="ucFile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
<asp:UpdatePanel ID="upPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<ucFile:FileHandler ID="fFile1" runat="server" />
</td>
<td>
<ucFile:FileHandler ID="fFile2" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
All file handling and processing is handled within the control, with an event when the upload to the file server is complete via a file name that was generated. When either button is clicked, the file name is always stored internal to the control in the last control's text box.
Control code:
<table style="width: 50%;">
<tr style="white-space: nowrap;">
<td style="width: 1%;">
<asp:Label runat="server" ID="lblFile" />
</td>
<td style="width: 20%;">
<asp:TextBox ID="txtFile" CssClass="backColor" runat="server" OnTextChanged="FileInformationChanged" />
</td>
<td style="width: 1%">
<%--<asp:Button runat="server" ID="btnUpload" CssClass="btn" Text="Attach" OnClick="UploadFile"/>--%>
<input type="button" id="btnUpload" class="btn" tabindex="30" value="Attach" onclick="SetupUpload();" />
</td>
<td style="width: 1%">
<%--<asp:Button runat="server" ID="btnClear" Text="Clear" CssClass="btn" OnClick="ClearTextValue"/>--%>
<input type="button" id="btnClearFile" class="btn" value="Clear" onclick="document.getElementById('<%=txtFile.ClientID%>').value = '';document.getElementById('<%=hfFile.ClientID%>').value = '';" />
</td>
<td style="width: 1%">
View
</td>
<td style="width: 1%">
<asp:HiddenField ID="hfFile" runat="server" />
</td>
</tr>
</table>
<script type="text/javascript">
var ItemPath = "";
function SetupUpload(File) {
ItemPath = File;
VersionAttach('<%=UploadPath%>', 'true');
}
function UploadComplete(File) {
document.getElementById('<%=txtFile.ClientID%>').value = File.substring(File.lastIndexOf("/") + 1);
document.getElementById('<%=hfFile.ClientID%>').value = File;
alert('<%=txtFile.Text %>');
alert('<%=ClientID %>')
}
function ViewLink(File, Alert) {
if (File != "") {
if (File.indexOf("../data/") != -1) {
window.open(File, '_blank');
}
else {
window.open('../data/<%=UploadPath%>/' + File, '_blank');
}
}
else if (Alert == "") {
alert('No file has been uploaded for this field.');
}
}
</script>
There are a couple of ways
a) use control.FindControl("hfFile")
b)
private HiddenField hfFile;
protected void hfFile_OnInit(object sender, EventArgs e){
hfFile = (HiddenField)sender;
}
The way I got this to work in my case was to put a title on the input button (client control), then passing the value of the clientid of the control that I wanted (textbox in this case) to the function in the onclick event (client event). I then "force" the consumer of the control to use this information when the button is clicked. The reason for the question here was to find out if there is a better way of accomplishing this within the control instead of making the consumer of the control handle the data. This does work for my purpose, it just doesn't seem as clean as I would have liked.
I have a master page and based on that master page I created a page with a TextBox and two Validation controls for RequiredValidator and RegularExpressionValidator and one ValidationSummary.
when pressing the enter key in TextBox, I expected that both validator show their errorMessage on validationSummary but thats not what happening it only works when I press the button on page.
According to this page I wrapped my code with <asp:panel> and a DefaultButton attribute but it didn't solve the problem.
http://www.codeproject.com/KB/aspnet/aspnet_Enter_key_problem.aspx
I want to know what the problem here is and whether there is any workaround?
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
**<asp:Panel runat="server" DefaultButton="EmailSend">**
<table style="width: 100%">
<tr>
<asp:ValidationSummary ID="EmailValidation" runat="server" CssClass="failureNotification"
ValidationGroup="EmailValidation" />
</tr>
<tr>
<td style="width: 76px">
Email:
</td>
<td class="style1">
<asp:TextBox ID="EmailForget" runat="server" Width="244px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="EmailRequiered" runat="server" ControlToValidate="EmailForget"
CssClass="failureNotification" ErrorMessage="RequiredFieldValidator" ValidationGroup="EmailValidation">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EmailRegular" runat="server" ControlToValidate="EmailForget"
CssClass="failureNotification" ErrorMessage="email required"
ValidationGroup="EmailValidation">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="width: 76px">
</td>
<td class="style1">
<asp:Button ID="EmailSend" runat="server" Text="send" Width="56px" ClientIDMode="Static" />
</td>
<td>
</td>
</tr>
</table>
**<asp:Panel>**
</asp:Content>
Try adding this code
<script type="text/javascript">
if (document.addEventListener) {//if Firefox
document.addEventListener("keypress", fireFoxHandler, true);
} else {
document.attachEvent("onkeyup", ieHandler);
}
function fireFoxHandler(evt) {
if (evt.keyCode == 13) {
document.getElementById("EmailSend").click();
}
}
function ieHandler(evt) {
if (evt.keyCode == 13) {
document.getElementById("EmailSend").click();
}
}
</script>
Found this solution here.
(I didn't check this in MasterPage scenario, please check...)
If you are using IE then according to the answers on these two pages:
ASP.NET enter key and form submit with no javascript
Enter button does not submit form (IE ONLY) ASP.NET
you only need to add the following to your form
<!-- Fix for IE bug submit on pressing "Enter") -->
<div style="display:none">
<input type="text" name="hiddenText"/>
</div>
I solved this problem like this:
protected void Page_Load(object sender, EventArgs e)
{
textboxusername.Attributes.Add("onKeyPress", "javascript:if (event.keyCode == 13) __doPostBack('" + LinkButton1.UniqueID + "','')");
textboxpassword.Attributes.Add("onKeyPress", "javascript:if (event.keyCode == 13) __doPostBack('" + LinkButton1.UniqueID + "','')");
}
and this is the link..
<asp:LinkButton ID="LinkButton1" runat="server" class="btn" OnClick="LinkButton1_Click">
I have the following code. It works as is, but... I am not always going to have an even number of items in the RSS feed So, at the end of the table, I might have only one table cell on the last row. So, is there a way to count the number of ItemTemplates and AlternatingItemTemplate, so if it is an odd number I would be able to add another cell <td> </td></tr> and close the table row?
<asp:XmlDataSource ID="SomeFeed" DataFile="TestSomeRSS.xml" XPath="rss/channel/item" runat="server"></asp:XmlDataSource>
<asp:ListView ID="SomeFeedScroller" DataSourceID="SomeFeed" ItemPlaceholderID="SomePlcID" runat="server">
<LayoutTemplate>
<table id="ListingsTable" cellpadding="0" cellspacing="0" align="center">
<asp:PlaceHolder ID="SomePlcID" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</ItemTemplate>
<AlternatingItemTemplate>
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
Thanks in advance for your help.
I'm not sure what you're asking, but why not just put a complete row in the ItemTemplate and AlternatingItemTemplate, like this:
<ItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</AlternatingItemTemplate>
That way you don't have to figure it out yourself - just let the control render itself.
EDITED TO ADD
Looking at your posted code again, it looks like you might have been attempting one row of alternating cell styles. I think you misunderstood the intent of the ItemTemplate and AlternatingItemTemplates; they usually deal with the fields (columns) of a given record.
In this case, you'd have the first RSS feed item in an ItemTemplate, then the second RSS feed item in an AlternateItemTemplate (i.e., another row), then the third RSS feed item in an ItemTemplate and so on.
I hope this helps - if I've misunderstood what you're trying to do let me know.
2nd Edit
Based on the example layout posted in the comments, I think the DataList Class would be a better option, as you can easily specify multiple columns (using the RepeatColumns property). Something like this:
<asp:XmlDataSource ID="SomeFeed" DataFile="TestSomeRSS.xml" XPath="rss/channel/item" runat="server">
</asp:XmlDataSource>
<asp:DataList ID="SomeFeedScroller" DataSourceID="SomeFeed"
RepeatColumns="2" RepeatDirection="Horizontal"
RepeatLayout="Table" runat="server">
<ItemStyle CssClass="bnotes" Vertical-Align="top" Width="325px" />
<AlternatingItemStyle CssClass="bnotes" vertical-Align="top" Width="325px" />
<ItemTemplate>
<%# XPath("title")%><br />
<%# XPath("description")%>
</ItemTemplate>
<AlternatingItemTemplate>
<%# XPath("title")%><br />
<%# XPath("description")%>
</AlternatingItemTemplate>
</asp:DataList>
The above is not tested, but the general idea was to keep the formatting as close to what was in the ListView as possible.
Another possible approach might be something similar to this thread on having multiple columns in a Repeater control: Multiple columns in a repeater.
The DataList control supports editing, selecting, updating, etc like ListView. The Repeater control does not.
I have some checkboxes in vb.net code.
<tr>
<td colspan="2">
<asp:CheckBox ID="chkbxCreateAmendOrg" runat="server" Checked="False" Text="Create/Amend Organisation" />
</td>
<td colspan="2">
<asp:CheckBox ID="chkbxCreateAmendCPUser" runat="server" Checked="False" Text="Create/Amend CP User" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="chkbxDeleteOrg" runat="server" Checked="False" Text="Delete Organisation" />
</td>
<td colspan="2">
<asp:CheckBox ID="chkbxDeleteCPUser" runat="server" Checked="False" Text="Delete CP User" />
</td>
</tr>
I want to give alert to user if they have not selected atleast one. Can i have jquery code for this
You can select all the not checked checkboxes and check the length or size() of the jQuery object:
if ($('input:checkbox:not(:checked)').length > 0) {
// some checkboxes not checked
}
Something like this should get it done...
$(document).ready(function() {
// get all checked
var checkboxes = $("input:checkbox:checked");
if(checkboxes.size() == 0)
alert("Please mark a checkbox!");
});
The following code print an alert for each checkbox not flagged:
$("input:not(:checked)").each(function(){
alert( $(this).attr("id") + " isn't checked!" );
});
See also the selectors
I advice use jQuery Validation plugin. It is very simple to use and so elegant (nice way to display error messages).
Check that example. (There are two radio buttons which one should be checked.)