<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Always">
<ContentTemplate>
<asp:ListView ID="EditModeListView" runat="server" DataSourceID="DataSourceWrite">
<itemtemplate>
<tr class="cat" onclick="return ApplyTRToggle(this);">
<td colspan="5"><img src="/_layouts/images/COLLAPSE.GIF" class="toggle-img"/> <%# Eval("Cat.CategoryName")%></td>
</tr>
<asp:ListView ID="SubListView" runat="server" DataSource='<%# Eval("Blocks") %>' >
<ItemTemplate>
<tr class="sec" onclick="return ApplyTRToggle(this);">
<td></td>
<td><img src="/images/COLLAPSE.GIF" /><%# Eval("Block.CategoryName")%> </td>
<td></td>
<td><%# Eval("StringFormat") != null ? String.Format(Eval("StringFormat").ToString(), Eval("BlockSum")):Eval("BlockSum") %></td>
<td>
<asp:ListView ID="SuberListView" runat="server" DataSource='<%# Eval("Crits") %>' >
<ItemTemplate>
<tr>
<asp:HiddenField ID="Identifier" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "ValueID")%>' />
<td></td>
<td><%# Eval("Crit.CategoryName")%></td>
<td><%# Eval("CritUnit")%></td>
<td>
<asp:HiddenField runat="server" ID="IsDecimalController" Value='<%# DataBinder.Eval(Container.DataItem, "IsDecimal")%>' />
<asp:TextBox runat="server" ID="ValueControl" Text='<%# DataBinder.Eval(Container.DataItem, "CritSum")%>' MaxLength="12"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="ErrorMSG" ValidationGroup="NumbersValidation" ControlToValidate="ValueControl" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression='<%# Const.FLOAT_DIGITALS%>' ValidationGroup="NumbersValidation" ErrorMessage="ErrorMSGG" ControlToValidate="ValueControl" Display="Dynamic" />
</td>
<td><%# DataBinder.Eval(Container.DataItem ,"Crit.Comment")%></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<div ID="itemPlaceholder" runat="server"></div>
</LayoutTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<tr ID="itemPlaceholder" runat="server"></tr>
</LayoutTemplate>
</asp:ListView>
</itemtemplate>
<layouttemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<div runat="server" ID="itemPlaceholder">
</div>
</table>
<div class="indicators-toolbar">
<asp:Button runat="server" ID="saveButton" Text="Save" ValidationGroup="NumbersValidation" CausesValidation="true" onclick="saveButton_Click"/>
<asp:Button runat="server" ID="cancelButton" Text="Cancel" CssClass="ms-ButtonHeightWidth" CausesValidation="false" onclick="cancelButton_Click"/>
</div>
</layouttemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
that's in my usercontrol. the problem is when type no valid text or leave empty in <asp:TextBox runat="server" ID="ValueControl" Text='<%# DataBinder.Eval(Container.DataItem, "CritSum")%>' MaxLength="12"></asp:TextBox> fires requiredfield validator and shows error text.. then press submit button, nothing happens, but then after typing correct text in textboxes and no validator fires submit button does NOT work. How to solve the problem
while click on button fire a trigger in ajax.....
it may help to you
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgbtnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Related
I have a repeater that displays products, and the footer is input fields where you can choose a product from a db and add it to the repeater. The first field of the add line in the footer is a RadComboBox (with product names) and I want to update the other input fields with info from the db when SelectedIndexChanged for that combobox.
The problem is finding those other controls in my code-behind function.
protected void ProductSelected(Object source, EventArgs e)
{
RadComboBox temp = (RadComboBox)source;
Product p = session.Query<Product>()
.Where(x => x.Name == temp.SelectedItem.Text)
.FirstOrDefault();
var repParent = temp.Parent;
//var repParent = ((UpdatePanel)temp.NamingContainer.FindControl("UpdateHardwareLine")).ContentTemplateContainer;
((TextBox)repParent.FindControl("AddPartNumber")).Text = p.PartNumber;
((TextBox)repParent.FindControl("AddPartCost")).Text = p.Cost.ToString();
((TextBox)repParent.FindControl("AddUnitPrice")).Text = p.Price.ToString();
((TextBox)repParent.FindControl("AddQuantity")).Text = p.DefaultQuantity.ToString();
}
I've tried this 2 ways. At first I put the UpdatePanel in the footer of the repeater, and I changed repParent to the commented version. This produced some really weird results where it updated the input fields, but now they're above my entire repeater o_0?
Then I pulled the updatepanel out of the repeater, and it updates, but it refreshes the entire page. I would settle for just updating the footer, but it'd be neat to get those add/delete buttons working in the same update panel. How should I go about setting this up so it just refreshes for whats in this well?
as requested;
<asp:Repeater ID="repHW" runat="server" OnItemCommand="rep_ItemCommand">
<HeaderTemplate>
<table style="width:100%; padding-bottom:10px" id="HWtable">
<tr style="font-weight: bold"><td>Product</td><td>Part Number</td><td>Cost</td><td>Unit Price</td><td>Quantity</td><td>Price</td><td>Delete</td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<asp:HiddenField ID="Category" Value="Hardware" runat="server"/>
<td><asp:Label ID="Product" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Name") %>' /></td> <!--TODO: make this clickable to edit -->
<td><asp:Label ID="PartNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.PartNumber") %>' /></td>
<td><asp:Label ID="PartCost" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Cost") %>' /></td>
<td><asp:Label ID="UnitPrice" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Price") %>' /></td>
<td><asp:Label ID="Quantity" runat="server" Text='<%# Eval("Quantity") %>' /></td>
<td><asp:Label ID="Price" runat="server" Text='<%# Eval("Total") %>' /></td>
<td><asp:Button class="btn btn-danger" ID="DeleteHardware" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%# Container.ItemIndex %>'/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<asp:UpdatePanel ID="UpdateHardwareLine" updatemode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddProduct" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><telerik:RadComboBox runat="server" ID="AddProduct" ClientIDMode="static" Filter="Contains" EnableLoadOnDemand="true" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadProductsByCategory"/></td>
<td><asp:TextBox runat="server" ID="AddPartNumber" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddPartCost" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddUnitPrice" ClientIDMode="static"/></td>
<td><asp:TextBox runat="server" ID="AddQuantity" ClientIDMode="static"/></td>
<td><asp:Button class="btn btn-success" ID="AddHardware" runat="server" Text="Add" CommandName="Add" CommandArgument='<%# DataBinder.Eval(Container, "ItemIndex") %>' onClientClick="return EmptyFieldCheck('Hardware');"/></td>
</ContentTemplate>
</asp:UpdatePanel>
</tr></table>
</FooterTemplate>
</asp:Repeater>
You could display the content of the footer in a separate table. Something like this:
<FooterTemplate>
<tr>
<td colspan="7">
<asp:UpdatePanel ID="UpdateHardwareLine" updatemode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddProduct" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<table style="width:100%;">
<tr>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><telerik:RadComboBox runat="server" ID="AddProduct" ClientIDMode="static" Filter="Contains" EnableLoadOnDemand="true" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadProductsByCategory"/></td>
...
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</FooterTemplate>
The challenge would be to get that inner table aligned properly with the outer one. You would probably need to set CellPadding="0" and CellSpacing="0" for both tables as a first step.
I am facing problems while using the ListView Control in asp.net
I used two buttons links in a ListView ItemTemplate. For both buttons, I used Command Name and Command Argument. But first one is working fine and the second one is giving errors. I.e.
System.InvalidOperationException: Insert can only be called on an insert item. Ensure only the InsertTemplate has a button with CommandName=Insert.
If I want to add the InsertTemplate, where do we have to place it?
I am copying my code. Please help me.
Design View :
<asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1" GroupItemCount="2" OnPagePropertiesChanging="ListView1_PagePropertiesChanging" DataKeyNames="InventoryID" OnItemCommand="ListView1_ItemCommand">
<LayoutTemplate>
<table width="100%">
<tr style="background-color:lightblue;color:blue;text-align:center;font-size:25px;font-weight:bold">
<td colspan="2">Available Books</td>
</tr>
<asp:PlaceHolder ID="groupPlaceHolder1" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder ID="itemPlaceHolder1" runat="server"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<table cellpadding="2" cellspacing="0" border="1" style="width:100%;height:100px; border:dashed 1px #04AFEF;background-color:#B0E2F5">
<tr>
<td>
<asp:Button ID="btnReview" runat="server" Text="Review" CommandName="Select" CommandArgument='<%# Eval("InventoryID") %>'/>
</td>
<td></td>
<td>
<asp:Button ID="btnAddToCart" runat="server" Text="Add To Cart" CommandName="Insert" CommandArgument='<%# Eval("InventoryID") %>' />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</asp:ListView>
Well you can insert a InsertItemTemplate like here :
<InsertItemTemplate>
<tr style="background-color:#D3D3D3">
<td valign="top">
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' /><br />
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' /><br />
<asp:Label runat="server" ID="EmailLabel"
AssociatedControlID="EmailTextBox" Text="E-mail" />
<asp:TextBox ID="EmailTextBox" runat="server"
Text='<%#Bind("EmailAddress") %>' />
</td>
<td>
<asp:LinkButton ID="InsertButton" runat="server"
CommandName="Insert" Text="Insert" />
</td>
</tr>
</InsertItemTemplate>
Used From : https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.insertitemtemplate(v=vs.110).aspx
what I do wrong?
<asp:Panel ID="pnlProductUnits" runat="server" Width="100%">
<asp:Repeater ID="repProductUnits" runat="server" EnableViewState="true" onitemcommand="Button_ItemCommand">
<HeaderTemplate>
<table class="grid" width="100%">
<tbody>
<tr>
<th align="left">test1</th>
<th align="left">test2</th>
<th align="left">test3</th>
<th width="50"></th>
</tr>
</tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# ((DBData.Catalog.ProductU)Container.DataItem).PrimaryUnitName%>
</td>
<td align="center">
<%# ((DBData.Catalog.ProductU)Container.DataItem).SecondaryUnitName%>
</td>
<td align="center">
<%# ((DBData.Catalog.ProductU)Container.DataItem).Quantity%>
</td>
<td style="display:none">
<asp:Label ID="PrimaryUnitID" runat="server"
Text="<%# ((DBData.Catalog.ProductU)Container.DataItem).PrimaryUnitID%>">
</asp:Label>
<asp:Label ID="SecondaryUnitID" runat="server"
Text="<%# ((DBData.Catalog.ProductU)Container.DataItem).SecondaryUnitID%>">
</asp:Label>
</td>
<td align="center">
<asp:Button id="btRemove" runat="server" commandname="deleteProductUnit" Text="Delete">
</asp:Button>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:DropDownList ID="ddlPrimaryUnit" runat="server" ValidationGroup="grpQuantity">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ErrorMessage="*"
Display="Dynamic" Text="*" ControlToValidate="ddlPrimaryUnit" ValidationGroup="grpQuantity" ForeColor="#FF3300">
</asp:RequiredFieldValidator>
</td>
<td>
<asp:DropDownList ID="ddlSecondaryUnit" runat="server" ValidationGroup="grpQuantity">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" Display="Dynamic" Text="*" ControlToValidate="ddlSecondaryUnit" ValidationGroup="grpQuantity" ForeColor="#FF3300"></asp:RequiredFieldValidator>
</td>
<td>
<asp:TextBox ID="txtQuantity" runat="server" placeholder="select value" ClientIDMode="Static"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" ControlToValidate="txtQuantity" ValidationGroup="grpQuantity" ForeColor="#FF3300"></asp:RequiredFieldValidator>
</td>
<td colspan="20">
<asp:Button id="btNew" runat="server" commandname="addProductUnit" Text="Add"
CommandArgument="test" ValidationGroup="grpQuantity"> </asp:Button>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
I suspect your problem is related to the validator knowing what the DropDownList's original selection was and whether or not something has been selected. You may need to add an InitialValue to the required field validator.
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="*" Display="Dynamic" Text="*"
ControlToValidate="ddlSecondaryUnit" ValidationGroup="grpQuantity"
ForeColor="#FF3300" InitialValue=""></asp:RequiredFieldValidator>
Depending on your DropDownList's datasource, that value may be something like "Please Select" or maybe just blank.
I am attempting to get the row and column location of a text boxes OntextChanged.
I can get the column location if I do this:
TextBox txtScore = sender;
ListViewItem item = (ListViewItem)txtScore.NamingContainer;
int col = ((ListView)item.NamingContainer).DataKeys(item.DataItemIndex).Values(0);
which works until I convert the snippet below to a user control.
Code Snippet
<asp:ListView ID="techs" runat="server" ItemPlaceholderID="lvItemPlaceholder" DataKeyNames="Number"
OnItemDataBound="techs_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
Tech
<%# Eval("Number")%>
</td>
<td>
<asp:TextBox ID="tech" runat="server" Text='<%# Eval("Name") %>' />
</td>
<asp:ListView ID="scorePatterns" runat="server" ItemPlaceholderID="lvScorePatternsItemPlaceholder"
OnItemDataBound="scorePatterns_ItemDataBound" DataKeyNames="Ref">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvScorePatternsItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<td>
<table>
<asp:ListView ID="scores" runat="server" ItemPlaceholderID="lvScoresItemPlaceholder"
OnItemDataBound="scores_ItemDataBound" DataKeyNames="Ref,Instance">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvScoresItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox runat="server" ID="txtScore" Width="50" AutoPostBack="true" OnTextChanged="txtScore_TextChanged" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
</td>
</ItemTemplate>
</asp:ListView>
<td>
<asp:Label runat="server" ID="lblDate" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
<asp:ListView ID="lvWallPosts" runat="server"
onitemcommand="lvWallPosts_ItemCommand" InsertItemPosition="LastItem">
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblWallPosts"
style="width:460px">
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<tr id="Tr2" style="height:72px" runat="server">
<td valign="top" class="EmployeeInfo">
<p>
<div class="wallmark"><asp:Image ID="imgFile" runat="server" CssClass="friendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"ByUsername").ToString() %>' />
<asp:Label ID="lblFrom" runat="server" Text='<%#Eval("ByUsername") %>' Font-Size="0.9em" Font-Underline="false" /><br />
<asp:Label ID="lblMessage" runat="server" Text='<%#Eval("Message") %>' Font-Size="0.9em" Font-Underline="false"/></div>
<asp:LinkButton CssClass="shareText" runat="server" ID="lblComment" CommandArgument='<%# Eval("Id") %>' CommandName="Insert" Font-Size="0.9em" Font-Underline="false">Comment</asp:LinkButton>
<asp:LinkButton CssClass="shareText" runat="server" ID="lbShare" CommandArgument='<%# Eval("Id") %>' CommandName="Share" Font-Size="0.9em" Font-Underline="false">Share</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I cant see the txtMessage control when I click on linkbutton comment.
try setting the linkbutton's commandname to "InitInsert" instead of "Insert"