Im working on a website built in .net
the following code
<asp:Repeater ID="RT_FAQ" runat="server">
<ItemTemplate>
<div class="faq-row" style="z-index: 976;">
<span class="itp-title"><%# DataBinder.Eval(Container.DataItem, "Question")%></span>
<div id="div1" style="display: none;"><%# DataBinder.Eval(Container.DataItem, "Answer")%></div>
</div>
</ItemTemplate>
</asp:Repeater>
outputs something along the lines of...
<div class="faq-row" style="z-index: 976;">
<span class="itp-title">Title</span>
<div id="div1" style="display: none;">Div contents</div>
</div>
<div class="faq-row" style="z-index: 976;">
<span class="itp-title">Title</span>
<div id="div1" style="display: none;">Div contents</div>
</div>
<div class="faq-row" style="z-index: 976;">
<span class="itp-title">Title</span>
<div id="div1" style="display: none;">Div contents</div>
</div>
<div class="faq-row" style="z-index: 976;">
<span class="itp-title">Title</span>
<div id="div1" style="display: none;">Div contents</div>
</div>
If you see all the divs are being given id="div1". I need to somehow give them all unique ID's so the first is div1, second div2 and so on.
Is this possible with .net?
Use the ItemIndex :
<div id="div<%# Container.ItemIndex %>" style="display: none;"><%# DataBinder.Eval(Container.DataItem, "Answer")%></div>
Just add + 1 if you want to start at 1 instead of 0.
Related
I am trying to prevent my modal from closing when keypress enter is entered in my modal asp textbox.
I have tried to wrap the textbox in another update panel and use an asynchronous postback trigger on textchanged, but thats not quite what I'm looking for. I am trying to create a text entry part which only updates when keypress enter is pressed and not when the text changes, I have also tried adding data-dismiss="modal" to the textbox itself like other pages have suggested, but this just means when I click on the textbox it shuts the modal.
<asp:UpdatePanel ID="upd_mdl_console" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<!-- Ryan Console-->
<div class="modal fade" data-dismiss="modal" data-toggle="modal" data-backdrop="static" data-keyboard="false" id="mdl_console" tabindex="-1" role="dialog">
<div class="modal-dialog2" role="document">
<div class="modal-content _dev_console">
<div class="modal-header _dev_console">
<h5 class="modal-title pull-left" id="H1" runat="server">
<asp:Label runat="server" ID="Label3" Text="DEV CONSOLE"></asp:Label></h5>
<button type="button" class="close pull-right" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<br />
</div>
<div class="modal-body">
<div class="panel-heading _dev_console">
<asp:Literal ID="devbox_line_5" runat="server" Text=""></asp:Literal>
<asp:Literal ID="devbox_line_4" runat="server" Text=""></asp:Literal>
<asp:Literal ID="devbox_line_3" runat="server" Text=""></asp:Literal>
<asp:Literal ID="devbox_line_2" runat="server" Text=""></asp:Literal>
<asp:Literal ID="devbox_line_1" runat="server" Text=""></asp:Literal>
<asp:UpdatePanel ID="upd_mdl_txt" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txt_Devbox" class="form-control _dev_console" runat="server" autocomplete="off"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="panel-heading _dev_console">
<div class="input-group" style="margin-bottom: 10px; width: 100%">
</div>
</div>
</div>
<div style="clear: both"></div>
<div class="modal-footer _dev_console">
<asp:Label ID="Label4" runat="server" Text="Label" Visible="false"></asp:Label>
<%-- <asp:Button ID="Button1" OnClick="lnk_go_Click" class="btn btn-success" runat="server" AutoPostBack="false" Text="Create"></asp:Button>--%>
<button type="button" class="btn btn-secondary _dev_console" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I use the following snippet to disable enter in textboxes. This also prevents triggering of a form post when pressing enter inside a textbox. It might work for preventing the closure of the modal also.
$('input').keypress(function (e) {
return e.keyCode !== 13;
});
If you want to disable the enter in the modal only you could do something like this
$('.modal-body input').keypress(function (e) {
return e.keyCode !== 13;
});
Here my page :
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<%# Register Assembly="Microsoft.ReportViewer.WebForms" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:HiddenField ID="hdnfromDate" Value="" runat="server" />
<asp:HiddenField ID="hdntoDate" Value="" runat="server" />
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Issue Invoice</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form id="reused_form" runat="server">
<p>
Send invoice to...
</p>
<div class="form-group">
<label for="name">
To:</label>
<input type="text" class="form-control"
id="name" name="name" readonly maxlength="50" runat="server">
</div>
<div class="form-group">
<label for="email">
CC:</label>
<input type="email" ID="cc" class="form-control" runat="server" multiple>
</div>
<div class="form-group">
<strong><i>Note:</i><small> <i>The invoice can not be edited after issuing.</i></small></strong>
</div>
<asp:LinkButton CssClass="btn btn-warning m-btn btn-block btn-lg m-btn--custom m-btn--icon m-btn--air " OnClick="Onbtn3_Click" Text="Issue Invoice " ID="LinkButton3" runat="server"></asp:LinkButton>
</form>
<div id="success_message" style="width: 100%; height: 100%; display: none;">
<h3>Sent your message successfully!</h3>
</div>
<div id="error_message"
style="width: 100%; height: 100%; display: none;">
<h3>Error</h3>
Sorry there was an error sending your form.
</div>
</div>
</div>
</div>
</div>
In cs File i am trying to access email value using cc.Value as for email textbox id is cc. But it always gets empty string. In my default master page i have a form tag which runs at server so if i keep this modal in a form runat server then gives me error saying page can have only one form tag. Please can anyone help me out. Thanks in advance
This may help
There is Text property available, so you can use textBox.Text to get textbox contian. In your case cc.Text.
Try textBox.text(). Should work.
As Html 5 type=“email” control is not available using runat attribute, you can access TextBox like below:
<asp:TextBox ID="txtBoxCc" runat="server" TextMode="Email"></asp:TextBox>
Now in codebehind you can access it like txtBoxCc.Text
Also, you have to put it like below:
if(!Page.IsPostBack) {
string cc = txtBoxCc.Text;
}
I am having an issue with my Asp.NET app, in the HTML section, basically the issue comes from the EVAL value which is the "Id" properly, so I've tried using an RadioButton and Input, but any of them work properly.
This is my Asp.NET code.
<div class="row justify-content-center">
<div class="col-lg-3">
<div class="item">
<input runat="server" id="AnswerID<%# Eval("Id") %>_Nunca" type="radio" name="GrupID<%# Eval("Id") %>" value="Company" class="required">
<label for="AnswerID<%# Eval("Id") %>_Nunca">
<img src="Content/img/seo_icon_1.svg" alt="">
<strong>Nunca</strong>No, Nunca
</label>
</div>
</div>
<div class="col-lg-3">
<div class="item">
<input runat="server" id="AnswerID<%# Eval("Id") %>_Aveces" name="GrupID<%# Eval("Id") %>" type="radio" value="Private User" class="required">
<label for="AnswerID<%# Eval("Id") %>_Aveces">
<img src="Content/img/seo_icon_2.svg" alt="">
<strong>A veces</strong>Si, Algunas veces
</label>
</div>
</div>
<div class="col-lg-3">
<div class="item">
<input runat="server" id="AnswerID<%# Eval("Id") %>_Siempre" name="GrupID<%# Eval("Id") %>" type="radio" value="Private User" class="required">
<label for="AnswerID<%# Eval("Id") %>_Siempre">
<img src="Content/img/seo_icon_3.svg" alt="">
<strong>Siempre</strong>Si, Siempre
</label>
</div>
</div>
</div>
This is the error:
Server Tag is not well formed.
I am not sure what's the issue, I have seen several similar questions, but no gives a real answer.
Thanks in advance.
I haven't done this in ages, but it looks like you have the double quotes nested. Try changing some of them to single quotes.
Try
<div class="item">
<input runat="server" id="Radio1" type="radio" name='GrupID<%# Eval("Id") %>' value="Company" class="required"/>
<label for="AnswerID<%# Eval("Id") %>_Nunca">
<img src="Content/img/seo_icon_1.svg" alt=""><strong>Nunca</strong>No, Nunca</label>
</div>
I have got an ASP ListView, bound programmatically to its DataSource at runtime.
Firefox and Chrome browsers have the issue where ONLY the first record of the ListView is causing the SelectedIndexChanged/Changing events to fire. All other selected records (2nd, 3rd, 4th record etc) are causing a Postback only, without the SelectedIndecChanged/Changing events being fired.
The strange thing, is that Internet Explorer fires the SelectedIndexChanged/Changing events on every record (not just the first record).
Does anyone know what I may be doing wrong?
<asp:ListView ID="lvUsersShoppingCart" runat="server" DataKeyField="ProductID" DataKeyNames="ProductID" OnSelectedIndexChanged="lvUsersShoppingCart_SelectedIndexChanged">
<ItemTemplate>
<div class="top-buffer">
<div class="row">
<div class="col-sm-3">
<asp:Image ID="imgProductThumbnail" class="img-responsive" runat="server" ImageUrl='<%# Eval("ThumbnailImageLocation")%>' />
</div>
<div class="col-sm-9">
<form class="form-horizontal">
<div class="form-group">
<strong>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName")%>' /></strong>
</div>
<div class="form-group">
<asp:Label ID="lblProductShortDescription" runat="server" Text='<%# Eval("ProductShortDescription")%>' />
</div>
<div class="form-group">
$<asp:Label ID="lblProductPrice" runat="server" Text='<%# Eval("ProductPrice")%>' />
(AUD)
</div>
<div class="form-group hidden">
<div class="col-sm-3">
<label for="lblProductQuantity" class="control-label">Quantity</label>
</div>
<asp:Label ID="lblProductQuantity" class="input-sm" runat="server" Text='<%# " x " + Eval("ProductQuantity").ToString%>'></asp:Label>
<asp:Button ID="btnEditQuantity" runat="server" Text="Change Qty" CssClass="btn btn-link" CommandName="Edit" />
</div>
<div class="form-group">
<asp:Button ID="btnDelete" runat="server" Text="Remove" CssClass="btn btn-danger" CommandName="Select" />
</div>
</form>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
The problem is caused by the form element in your ItemTemplate:
<form class="form-horizontal">
...
</form>
You can get the correct behavior if you replace it by another type of container (typically a div):
<div class="form-horizontal">
...
</div>
I have this code in my control it is basically a control where the user enters a postcode and then clicks the check availability button - this then in turn calls an API and displays the address details in the update panel below.
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="UpdatePanel_PostCode">
<ContentTemplate>
<asp:Panel runat="server" ID="Panel_PostCode" CssClass="form-row group" >
<div class="textbox-group">
<div class="textbox-group-row">
<div class="label-textbox">
<asp:Label runat="server" ID="Label_PostCodeToCheck" AssociatedControlID="TextBox_PostCodeToCheck"
Text="Postcode"></asp:Label>
</div>
<div class="input-text">
<asp:TextBox runat="server" ID="TextBox_PostCodeToCheck"></asp:TextBox>
</div>
</div>
<div class="textbox-group-row">
<div class="find-address">
<span class="extra">
<asp:Button runat="server" ID="Button_AddressCheck" CssClass="button dis small"
Text="Find Address" OnClick="Button_AddressCheck_OnClick" ClientIDMode="AutoID"/>
</span>
</div>
<div class="input-text">
<asp:UpdateProgress ID="progressPanel" runat="server" AssociatedUpdatePanelID="UpdatePanel_PostCode">
<ProgressTemplate>
<div id="CheckAvailMsg" runat="server" style="height: 24px; margin-top: 0.5em;">
<img id="ImageLoading" width="24px" height="24px" src="../images/loading.gif" alt="" style="float: left; padding-right: 0.5em;" />
<p id="domainCheckerText" style="float: left; padding-top: 0.3em; color: #000;">Checking Availability..</p>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</div>
<asp:Panel ID="Panel_Error" runat="server" CssClass="error" Visible="False">
<asp:Literal runat="server" ID="Literal_Error"></asp:Literal>
</asp:Panel>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
However when I click the Find address button the Update progress does not show - i've exhausted a number of resources but still cannot find a solution.