I would like to replace js windows by bootstrap popover in few pages but I have two issues and I don't find any solutions.
First, if I click on the button to display the popover, required fields are fired directly. Even if I fill in it the message "xx is a required field" stay displayed.
Second, when I try to save my data. Every fields contain an extra character ",". So if I put 10 in the price field in code behind the value of my field is "10,"
Thanks for your help :)
My code:
<asp:Button ID="btnAdd" runat="server" Text="add" CssClass="btn btn-info"data-toggle="popover" data-placement="top" title="add something" ValidationGroup="vgAdd" />
<div id="testBox" class="hide">
<asp:ValidationSummary ID="vsTest" runat="server" ValidationGroup="vgAdd" DisplayMode="BulletList" ShowMessageBox="false" ShowSummary="false" />
<div class="row">
<div class="form-group col-sm-6">
<asp:Label ID="lblPrice" runat="server" Text="price" AssociatedControlID="txtPrice" CssClass="control-label"></asp:Label>
<div class="input-group">
<span class="input-group-addon">$</span>
<asp:TextBox ID="txtPrice" runat="server" CssClass="form-control" MaxLength="12"></asp:TextBox>
</div>
<asp:CompareValidator ID="cvPrice1" runat="server" Display="None" ValidationGroup="vgAdd" ControlToValidate="txtPrice"
ErrorMessage="price is invalid." ValueToCompare="0" Type="Double" Operator="GreaterThan"></asp:CompareValidator>
<asp:CompareValidator ID="cvPrice" runat="server" Display="None" ValidationGroup="vgAdd" ControlToValidate="txtPrice"
Type="Double" Operator="DataTypeCheck" ErrorMessage="price is invalid."></asp:CompareValidator>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ValidationGroup="vgAdd" ControlToValidate="txtPrice"
ErrorMessage="Default price is a required field." SetFocusOnError="True" Display="Dynamic" />
</div>
<div class="form-group col-sm-6">
<asp:Label ID="lblDesc" runat="server" Text="Description" AssociatedControlID="txtDesc" CssClass="control-label"></asp:Label>
<asp:TextBox ID="txtDesc" runat="server" CssClass="form-control" TextMode="MultiLine" MaxLength="255"></asp:TextBox>
</div>
</div>
<div class="clearfix">
<asp:Button ID="btnSave" runat="server" ValidationGroup="vgAdd" CausesValidation="true"
CssClass="btn btn-primary pull-right"
OnClick="btnSaveTest_Click" Text="Save" />
</div>
</div>
$("[data-toggle=popover]").popover({
html: true,
content: function () {
return $('#testBox').html();
}
});
To fix the first problem you need to remove ValidationGroup="vgAdd" from #btnAdd; you don't want to validate form when this button is clicked.
Regards the second one - there is nothing within your html code what could append comma. You must have something in the back-end code or javascript. I suggest you to debug all the way down from the point when the button #btnSave is clicked - first javascript, then code behind.
Related
I am having lots of problems with my dropdownlist. My dropdownlist controls disappear after postback.
The idea is that if in the drop down list I choose Spain, the ddlProvincia control shows the Spanish provinces. However, if I choose any country other than Spain, I should show the textbox "tbProvinciaNombre".
The problem is that when I select a country in the "ddlPais" control the list items of this control and "ddlProvincia" disappear completely.
Any help is welcome.
Thank you.
<asp:UpdatePanel ID="upProvinciaNombre" runat="server" UpdateMode="Conditional" class="col-md-6 form-group">
<ContentTemplate>
<!-- Provincia -->
<div id="panelDdlProvincia" runat="server" visible="true">
<asp:Label runat="server" AssociatedControlID="ddlProvincia">Provincia</asp:Label><span class="requerido">*</span>
<asp:DropDownList ID="ddlProvincia" runat="server" CssClass="form-control selectpicker" />
<asp:RequiredFieldValidator ID="rfvddlProvincia" runat="server" ErrorMessage="Seleccione una opción" CssClass="invalid-feedback" Text="*" InitialValue="none" ControlToValidate="ddlProvincia" ValidationGroup="ValidationButton"></asp:RequiredFieldValidator>
<ajax:ValidatorCalloutExtender ID="vceRfvddlProvincia" runat="server" TargetControlID="rfvddlProvincia" HighlightCssClass="error" CssClass="oculto" />
</div>
<!-- Provincia Nombre -->
<div id="panelTbProvinciaNombre" runat="server" visible="false">
<asp:Label runat="server" ID="lbProvinciaNombre" AssociatedControlID="tbProvinciaNombre">Provincia</asp:Label><span class="requerido">*</span>
<asp:TextBox ID="tbProvinciaNombre" runat="server" CssClass="form-control"></asp:TextBox>
<div>
<asp:RequiredFieldValidator ID="rfvTbProvinciaNombre" runat="server" CssClass="invalid-feedback" ControlToValidate="tbProvinciaNombre" Display="Dynamic" ValidationGroup="ValidationButton" ErrorMessage="Introduzca una provincia válida" />
<ajax:ValidatorCalloutExtender ID="vceRfvTbProvinciaNombre" runat="server" TargetControlID="rfvTbProvinciaNombre" HighlightCssClass="error" CssClass="oculto" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<!-- Pais -->
<asp:UpdatePanel ID="upPais" runat="server" UpdateMode="Conditional" class="col-md-6 form-group">
<ContentTemplate>
<asp:Label runat="server" AssociatedControlID="ddlPais">Pais</asp:Label><span class="requerido">*</span>
<asp:DropDownList ID="ddlPais" runat="server" CssClass="form-control selectpicker" AutoPostBack="true" />
<asp:RequiredFieldValidator ID="rfvddlPais" runat="server" ErrorMessage="Seleccione una opción" CssClass="invalid-feedback" Text="*" InitialValue="none" ControlToValidate="ddlPais" ValidationGroup="ValidationButton"></asp:RequiredFieldValidator>
<ajax:ValidatorCalloutExtender ID="vceRfvddlPais" runat="server" TargetControlID="rfvddlPais" HighlightCssClass="error" CssClass="oculto" />
</ContentTemplate>
</asp:UpdatePanel>
<!-- Políticas -->
<div class="col-md-12 form-group">
<div class="checkbox">
<asp:CheckBox ID="cbPoliticas" runat="server" />
<asp:Label runat="server" ID="politicas" AssociatedControlID="cbPoliticas">He leído y acepto la
<asp:HyperLink ID="hlkPoliticaPrivacidad" runat="server" Target="_blank" NavigateUrl="~/contenidos/privacidad.aspx" Text="política de privacidad" />
y el
<asp:HyperLink ID="hlkAvisoLegal" runat="server" Target="_blank" NavigateUrl="~/contenidos/avisoLegal.aspx" Text="aviso legal" />
del sitio web.
</asp:Label>
<div>
<asp:TextBox ID="tbFakeCv" runat="server" CssClass="oculto" />
<asp:CustomValidator runat="server" ID="cvCbPoliticas" ErrorMessage="Es obligatorio aceptar la política de privacidad" CssClass="error" Display="Dynamic" ControlToValidate="tbFakeCv" ValidateEmptyText="true" ValidationGroup="ValidationButton" />
<ajax:ValidatorCalloutExtender ID="vceCvCbPoliticas" runat="server" TargetControlID="cvCbPoliticas" HighlightCssClass="error" CssClass="oculto" />
</div>
</div>
</div>
The solution was really simple. In my case, I was using the class "selectpicker", but I assumed that this functionality was implemented in the .js file. But no, It was missing. Just add the following code in the .js file and everything is working like a charm.
Sorry. I just want to comment it because sometimes the frontend and backend are responsible of different people, and a error in one part could be a pain in the ass to the other member of the team.
// Selectpicker
if ($.fn.selectpicker) {
$('.selectpicker:not(.jQ_todos)').selectpicker();
$('.selectpicker.jQ_todos').selectpicker({ noneSelectedText: 'Todos' });
}
I have a form inside which I have a button1 which triggers the modal.
Inside modal window I have textboxes(to take some credentials) with validations and another button (button2) (type=button) containing onClick definition which is working fine if I provide good data, but when I provide no data in one of the text boxes and click on the button2 the complete page reloads and I get to my main page where I click on button1 and I see the validation messages.
The validation should appear just as the user clicks button2
I have looked around and tried couple of thing but cant figure out why is it happening,
I am using page routing in page_load is that the reason?
here is the code inside the modal in my html.aspx:
<form=from1 runat=server>
<div class="modal fade" id="logger_modal" tabindex="-1" role="dialog" aria-labelledby="logger_model1" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body align-content-center">
<asp:TextBox ID="textbox1" runat="server" Class="form-control" placeholder="sometext" onkeydown = "return (event.keyCode!=13);"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="message1" ControlToValidate="textbox1" EnableClientScript="false" Display="Dynamic" ></asp:RequiredFieldValidator>
<asp:TextBox ID="textbox2" runat="server" Class="form-control" placeholder="sometext" onkeydown = "return (event.keyCode!=13);"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="message2" ControlToValidate="textbox2" EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
</div>
<div class="modal-footer">
<asp:Button ID="close" runat="server" Text="Cancel" type="button" class="btn btn-secondary" data-dismiss="modal"/>
<asp:Button ID="button2" runat="server" Text="button2_text" type="button" class="btn btn-primary" CausesValidation="true" OnClick="OnClick_method" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</div>
</div>
</div>
Code inside ONClick_method in html.aspx.cs
if (Page.IsValid)
{
some code which works if i provide right values in textboxes
}
else
{
Label1.Text = "Please provide the details.";
}
This happens because your page does a postback and the page does a complete reload which results in closing the modal which causes probably the lose of values.
To prevent the page from completely reloading you can use a UpdatePanel for partial update of your page.
Example:
<div class="modal-body align-content-center">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="textbox1" runat="server" Class="form-control" placeholder="sometext" onkeydown="return (event.keyCode!=13);"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="message1" ControlToValidate="textbox1" EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:TextBox ID="textbox2" runat="server" Class="form-control" placeholder="sometext" onkeydown="return (event.keyCode!=13);"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="message2" ControlToValidate="textbox2" EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="button2" />
</Triggers>
</asp:UpdatePanel>
</div>
You only surround the part that needs to be partially updated so the modal won't close and set the control for the async postback to button2.
<div class="row">
<form class="form-inline">
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="tb_FName" CssClass="col-md-2 control-label">First Name</asp:Label>
<div class="col-md-10" >
<asp:TextBox runat="server" ID="tb_FName" CssClass="form-control" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="tb_FName"
CssClass="text-danger" ErrorMessage="The First Name field is required." SetFocusOnError="True" Display="Dynamic" />
</div>
</div>
<div class="form-group" style="float:right">
<asp:Label runat="server" AssociatedControlID="tb_LName" CssClass="col-md-2 control-label">Last Name</asp:Label>
<div class="col-md-10 ">
<asp:TextBox runat="server" ID="tb_LName" CssClass="form-control" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="tb_LName"
CssClass="text-danger" ErrorMessage="The Last Name field is required." SetFocusOnError="True" Display="Dynamic" />
</div>
</div>
</form>
</div>
There is a label and a textbox and another label and textbox .second label and textbox come in the second line.i need to come in the same line.i have put it in a row and used form-inline also..i tried changing the column space still t would not work.
you can use class= "col-md-3" to set all 3 items in row.
Adding my comment as an answer, before someone else does it....
Change col-md-10 to col-md-6 Bootstrap divides the website in grid with 12 columns. You can check Bootstrap for more information about the grid
I have two forms for login and registration.I am trying to use HTML5 validation. When i click the form to submit login, controls of registration is validated and vice versa.How do I prevent that? I know there is something called validation group but I guess that works only for the validationcontrols provided by .NET.
Here's my code:
<h2><em> Registration </em></h2>
<asp:TextBox ID="tb_uname" class="login_mem" runat="server" placeholder="Name" required></asp:TextBox> <br />
<asp:TextBox ID="tb_address" class="login_mem" runat="server" placeholder="Address" ></asp:TextBox> <br />
<asp:TextBox ID="tb_email" class="login_mem" runat="server" placeholder="Email" ></asp:TextBox> <br />
<asp:TextBox ID="tb_pass" class="login_mem" TextMode="Password" runat="server" placeholder="Password" ></asp:TextBox> <br />
<asp:Button ID="btn_reg" runat="server" Text="Registration" CausesValidation="false"
onclick="btn_reg_Click"/>
</div>
<div id="log">
<h2><em>Login </em></h2>
<asp:TextBox ID="tb_name" class="login_mem" runat="server" placeholder="username" required></asp:TextBox> <br />
<asp:TextBox ID="tb_password" class="login_mem" runat="server" placeholder="password"></asp:TextBox><br />
<asp:Button ID="btn_log" runat="server" Text="Login" onclick="btn_log_Click"/>
<asp:Label ID="error" runat="server"></asp:Label>
</div>
You can add the novalidate tag to your forms to prevent them from validating when submitting them.
<form action="demo_form.asp" novalidate>
Or you could add it to one or multiple forms using javascrit/query:
$(document).ready(function() {
$("form").attr('novalidate', 'novalidate');
});
I have a very basic form in a .Net page, it has 6 fields each with a requiredfieldvalidator attached. Everything works fine and the form is stopped if even one field is blank. I was asked to add a section with 2 radio buttons (I set one option as checked to avoid any validation on the field), now the form submits no matter if the fields have information in them or not.
Subset of default.aspx
<form id="form1" runat="server">
<div style="margin-bottom:10px;">
<label for="txtAgencyName">Name of Agency</label>
<asp:TextBox ID="txtAgencyName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAgencyName" runat="server" ErrorMessage="*Required" ControlToValidate="txtAgencyName" ValidationGroup="vg1" CssClass="rfvErrors"></asp:RequiredFieldValidator>
</div>
<div style="margin-bottom:10px;">
<label for="txtEmail">Email Address</label>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server" ErrorMessage="*Required" ControlToValidate="txtEmail" ValidationGroup="vg1" CssClass="rfvErrors"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail" runat="server" ErrorMessage="Invalid Email Address" CssClass="revErrors" ValidationExpression="(^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*#([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$)" ValidationGroup="vg1" ControlToValidate="txtEmail"></asp:RegularExpressionValidator>
</div>
<!-- This is the section that is breaking the validation -->
<div style="margin-bottom:10px;">
<asp:RadioButton ID="rbOwnershipAgent" runat="server" Checked="true" GroupName="Ownership" />
<asp:RadioButton ID="rbOwnershipReferral" runat="server" GroupName="Ownership" />
</div>
<!-- --------------------------------------------------- -->
<div style="margin-bottom:10px;">
<label for="txtAgencyContact">Agency Contact Name</label>
<asp:TextBox ID="txtAgencyContact" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAgencyContact" runat="server" ErrorMessage="*Required" ControlToValidate="txtAgencyContact" ValidationGroup="vg1" CssClass="rfvErrors"></asp:RequiredFieldValidator>
</div>
<div style="margin-bottom:10px;">
<label for="txtPhone">Telephone Number</label>
<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvTelephone" runat="server" ErrorMessage="*Required" ControlToValidate="txtPhone" ValidationGroup="vg1" CssClass="rfvErrors"></asp:RequiredFieldValidator>
</div>
<div>
<label for="ddlState">State</label>
<asp:DropDownList ID="ddlState" runat="server" AppendDataBoundItems="True">
<asp:ListItem Text="Select State" Value=""></asp:ListItem>
</asp:DropDownList>
</div>
<div style="margin-bottom:10px;">
<label for="taCarriers">In your agency, who are the carriers writing liquor liability for you today?</label>
<asp:TextBox ID="taCarriers" runat="server" TextMode="MultiLine" Rows="3"></asp:TextBox><asp:RequiredFieldValidator ID="rfvOtherCarriers" runat="server" ErrorMessage="*Required" ControlToValidate="taCarriers" ValidationGroup="vg1" CssClass="rfvErrors" style="margin-top:15px;"></asp:RequiredFieldValidator>
</div>
<div style="width:100%;margin-top:20px;border-bottom:1px solid #27a0d6"></div>
<asp:Button ID="btnSubmit" runat="server" Text="Submit »" name="bnSubmit" class="submit" ValidationGroup="vg1" />
</form>
Am I missing something simple as far as an attribute on the submit button or radio buttons? I'm just surprised that a built in .Net control is causing this kind of trouble for something this basic. Thanks for any help.