How to show textbox label name on Validation Summary - asp.net

Here's an input example with some validators
Validation Summary
<asp:ValidationSummary runat="server"
ID="ValidationSummary1"
DisplayMode="BulletList"
ValidationGroup="vgInformacaoInicial"
CssClass="alert validation-summary"
ShowSummary="true" />
<div class="form-group col-8 mx-auto text-center">
<asp:Label ID="lblCliente" runat="server" AssociatedControlID="txtCliente" Text="Cliente" />
<small><i class="fas fa-asterisk text-danger mb-2" style="font-size: 7px;"></i></small>
<asp:TextBox ID="txtCliente" runat="server" CssClass="form-control form-control-sm rounded border border-dark" placeholder="Cliente" />
<div class="valid-feedback feedback-icon">
<i class="fa fa-check"></i>
</div>
<div class="invalid-feedback feedback-icon">
<i class="fa fa-times"></i>
</div>
<asp:RequiredFieldValidator ID="rfvCliente" runat="server"
CssClass="server-validator"
ValidationGroup="vgInformacaoInicial"
SetFocusOnError="True"
ControlToValidate="txtCliente"
ErrorMessage="<b>Client:</b> Required Field."
Display="None">
</asp:RequiredFieldValidator>
</div>
Here is the problem, I want to show required field under every textbox and also on the Validation summary. This already does. Thing is, it's a mess and says Required field many times without any identification so I added the name in the required field error message but it becomes too long when it's under the textbox.
So short and simple... Is there a way i can show the label name referred by the validator on validation summary without having to write on error message and set display to none?

You will need to set ErrorMessage property of each validator to just the corresponding label name, and also set the HeaderText property of validation summary control to something like "Please input following fields:".
The same code snippet that you posted is modified with these changes as below.
<asp:ValidationSummary runat="server"
ID="ValidationSummary1"
DisplayMode="BulletList"
ValidationGroup="vgInformacaoInicial"
CssClass="alert validation-summary"
HeaderText="Please input following fields:"
ShowSummary="true" />
<div class="form-group col-8 mx-auto text-center">
<asp:Label ID="lblCliente" runat="server" AssociatedControlID="txtCliente" Text="Cliente" />
<small><i class="fas fa-asterisk text-danger mb-2" style="font-size: 7px;"></i></small>
<asp:TextBox ID="txtCliente" runat="server" CssClass="form-control form-control-sm rounded border border-dark" placeholder="Cliente" />
<div class="valid-feedback feedback-icon">
<i class="fa fa-check"></i>
</div>
<div class="invalid-feedback feedback-icon">
<i class="fa fa-times"></i>
</div>
<asp:RequiredFieldValidator ID="rfvCliente" runat="server"
CssClass="server-validator"
ValidationGroup="vgInformacaoInicial"
SetFocusOnError="True"
ControlToValidate="txtCliente"
ErrorMessage="Cliente"
Display="None">
</asp:RequiredFieldValidator>
</div>
You will end up with a validation summary that looks like what is shown below.

Related

ASP.Net Updatepanel Placement

I have a page with 3 fields on it. An amount (textbox), a payment terms (dropdown) (once, montly, quarterly, etc.) and an amount to be charged based on what is selected in the dropdown. The dropdown is set to autopostback=true. The operation works to calculate the amount to be charged, but pops back to the top of the page during postback. I know I need an updatepanel to do a partial postback, I just can't figure out how to code it or where to put it in my code. The attempts I have made seem to swallow the postback, and nothing happens.
This is the code without the updatepanel:
<div class="row form-group">
<label class="control-label col-md-4" for="lblTotal">Total Amount:<asp:textbox ID="lblTotal" runat="server" visible="true" borderstyle="None" ForeColor="#FFFFFF" BackColor="#FFFFFF"/></label>
<div class="col-md-3 "><div class="input-group"><span class="input-group-addon" id="lblDollar" style="border-color:#4B116F; border-width:2px; color:#4B116F;">$</span>
<asp:textbox ID="lblTotalAmount" Runat="server" Font-Bold="true" ReadOnly="false" class="form-control" aria-describedby="lblDollar" style="border-color:#4B116F; border-width:2px; color:#4B116F;" AutoPostBack="false"/></div></div>
<div class="col-md-3"><asp:rangeValidator id="rvalTotalAmount" ControlToValidate="lblTotalAmount" runat="server" type="Double" Minimumvalue="5.00" Maximumvalue="30000.00" ErrorMessage="For your security we limit online gifts to a range of $5.00 to $30,000.00." Text="*"></asp:rangeValidator><asp:CustomValidator ID="cvalDesignation" runat="server" errormessage="Please enter a designation." Text="*"/></div>
</div>
<div class="row form-group">
<label class="control-label col-md-4">Payment Terms: </label>
<div class="col-md-3">
<asp:DropDownList ID="ddlCCFrequency" Runat="server" class="ddl_styler_combo ddl-size dropdown-toggle" AutoPostBack="true" style="border-radius:4px; width:160px;"/>
</div>
<asp:TextBox ID="tbxAuthNetAmt" runat="server" visible="true" borderstyle="solid" ForeColor="#FFFFFF" BackColor="#FFFFFF"/>
</div>
<div class="row form-group">
<label class="control-label col-md-4">Card will be charged: </label>
<div class="col-md-3"><div class="input-group">
<span class="input-group-addon ddl_styler_combo" id="ccDollar" style="border-color:#4B116F; border-width:2px; color:#4B116F; font-weight:bold; height:33px;">$</span>
<asp:TextBox ID="tbxCardAmount" readonly="false" Runat="server" class="form-control ddl_styler_combo ddl-size" aria-describedby="ccDollar" style="border-color:#4B116F; border-width:2px; color:#4B116F; border-bottom-right-radius:4px; border-top-right-radius:4px;" />
</div></div>
<div class="col-md-2"><asp:CustomValidator id="cvalCardChargeSchedule" runat="server" enabled="true" ErrorMessage="Please specify a billing schedule" /></div>
</div>
"The attempts I have made seem to swallow the postback"
when this is happens its means that you have JavaScript errors.
From this code only the validator's can cause JavaScript errors - Remove them temporary to see if UpdatePanel working, and then add one by one to locate what is going wrong.
Alternative see for javacript errors as you have the page using the Web Browser Tools.

I have applied Materialize CSS but still not showing icons

I have applied Materialize CSS in my ASP.NET Project but still not showing icons..
Its just showing Icon name instead of Real Icon
And I Use 2 Asp Radio Buttons and bind with Materialized CSS ..
But now non of them are select-able
Can anyone help me
Thank you ....
Radio Button Code :
<div>
<asp:Label ID="lblMale" runat="server" class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="MALE">
<asp:RadioButton ID="MALE" runat="server" CssClass="mdl-radio__button" Text="MALE" GroupName="G"/><span class = "mdl-radio__label">MALE</span></asp:Label>
<asp:Label ID="lblFemale" runat="server" class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="FEMALE">
<asp:RadioButton ID="FEMALE" runat="server" CssClass="mdl-radio__button" GroupName="G" Text="FEMALE" /><span class = "mdl-radio__label">FEMALE</span></asp:Label></div>
Icon Code :
<div class="col-sm-6">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">face</i>
</span>
<div class="form-group label-floating">
<label class="control-label">First Name <small>(required)</small></label>
<asp:TextBox ID="txtFirst_Name" runat="server" CssClass="form-control
</asp:TextBox>
</div>
</div>
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">record_voice_over</i>
</span>
<div class="form-group label-floating">
<label class="control-label">Last Name <small>(required)</small></label>
<asp:TextBox ID="txtLast_Name" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</div>
<div>
<asp:Label ID="lblMale" runat="server" class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="MALE">
<asp:RadioButton ID="MALE" runat="server" CssClass="mdl-radio__button" Text="MALE" GroupName="G"/>
<span class = "mdl-radio__label">MALE</span>
</asp:Label>
<asp:Label ID="lblFemale" runat="server" class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="FEMALE">
<asp:RadioButton ID="FEMALE" runat="server" CssClass="mdl-radio__button" GroupName="G" Text="FEMALE" />
<span class = "mdl-radio__label">FEMALE</span>
</asp:Label>
</div>
</div>
Make sure you're loading the Material Icons font
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<i class="material-icons">face</i>

Asp.net - Stack Empty

In my asp.net webform project I'm trying to add asp:panel for search field. I need to use defaultbutton attribute.
<div class="input-group">
<asp:Panel ID="pnlSearch" runat="server" DefaultButton="btnSearch">
<input class="form-control" placeholder="Search" autocomplete="off" runat="server" onkeypress="searchclick('btnSearch',event);" id="txtSearch" />
<div class="input-group-btn">
<button class="btn btn-default" id="btnSearch" itemid="btnSeach" onserverclick="btnSearch_ServerClick" runat="server" type="submit"><i
class="glyphicon glyphicon-search"></i></button>
</div>
</asp:Panel>
</div>
When I try to do this I took error like.
error screen
If I just remove defaultbutton attribute the error is gone.

How to avoid that Bootstrap modal blocks all asp buttons inside or outside of modal, whether modal is shown or not

Asp.net 4.5 web form with masterpage, a listview and some asp buttons for different tasks, then a html button to trigger modal. Modal pops up looking good. No other buttons work. Asp button on modal does not fire event either.
I removed the modal div and everything worked fine.
I think that the modal has some sort of listening function that might intercept all other events, could that be the problem? The old ajax toolbox modal popup did not pose this problem.
Anyone know how I can fix this? The modal is really well suited for the user interaction, I hope I can get it to work.
EDIT: asp button event on modal does work. It's outside, when modal is not shown, that is the problem.
This is the top of my page form with btnEmpty that does not work:
Send bestilling
<%: Page.Title %>
<p class="text-danger">
<asp:Literal runat="server" ID="ErrorMessage" />
</p>
<br/>
<div class="row">
<section>
<asp:ListView ID="lvHandleliste" runat="server"
OnItemDataBound="lvHandleliste_ItemDataBound"
OnDataBound="lvHandleliste_DataBound"
EmptyDataText="Handlekurven er tom">
And this is the modal, it's put in the very bottom of the page contentplaceholder:
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="padding:20px 50px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title">Bestillingsinformasjon</h2>
</div>
<div class="modal-body" style="padding:40px 50px;">
<div class="form-group">
<label for="tbxBestillingsnr">Bestillingsnr </label>
<asp:TextBox ID="tbxBestillingsnr" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxBestillingsnr" Display="Dynamic"
CssClass="text-danger" ErrorMessage="" Text="Fyll ut!" />
</div>
<div class="form-group">
<label for="tbxReferanse">Vår ref </label>
<asp:TextBox ID="tbxReferanse" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxReferanse" Display="Dynamic"
CssClass="text-danger" ErrorMessage="" Text="Fyll ut!" />
</div>
<div class="form-group">
<label for="tbxAdresse">Leveringsadresse </label>
<asp:TextBox ID="tbxAdresse" runat="server" TextMode="MultiLine" Rows="4" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbxAdresse" Display="Dynamic"
CssClass="text-danger" ErrorMessage="" Text="Fyll ut!" />
</div>
<asp:Button ID="btnSend" runat="server" Text="Send bestilling" CssClass="btn btn-info btn-block" OnClick="btnSend_Click" />
</div>
<div class="modal-footer" style="padding:20px 50px;">
<button type="submit" class="btn btn-danger btn-default pull-left" data-dismiss="modal">
<span class="glyphicon glyphicon-remove"></span> Avbryt</button>
</div>
</div>
</div>
</div>
No response to my question but I finally found the answer myself. Here goes:
In my modal body I have some RequiredFieldValidators. These acted on all submit buttons on the page. So when the modal was hidden no submit could be done since the control fields required were not filled in.
The solution is to add all validator controls to a validation group, together with the one submit button their supposed to act on. Easy :-)
Hope this helps other people,
Siw

asp.net Do not validate Modal form when hidden

I have a modal form (bootstrap), I am using asp.net RequiredFieldValidtors for data entry validation. This validation should only fire when the modal is visible and the user is entering new values into the modal.
The problem I am having is that the validation triggers when the model form is not shown preventing my main page from accepting new data entry from. My modal is only used to add new values and is not part of the normal workflow on my main page.
I have been stuck on this for two days now and have tried many different things and just can't get it figured out.
Any suggestions on how to handle this while keeping my RequiredFieldValidator rules intact?
Thanks
Edit - Adding modal forms code.
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<div class="modal fade" id="modNewStakeholder" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Add Stakeholder</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label">First Name:</label>
<asp:TextBox class="form-control focus" ID="tFirstName" runat="server" AutoComplete="off" placeholder="First name is required"></asp:TextBox>
<asp:RequiredFieldValidator ID="rftFirstName"
runat="server" ErrorMessage="Required Field"
ControlToValidate="tFirstName" Display="Dynamic"
ValidationGroup="ValGroupNewStake"></asp:RequiredFieldValidator>
</div>
<div class="form-group">
<label class="control-label">Last Name:</label>
<asp:TextBox class="form-control" ID="tLastName" runat="server" AutoComplete="off" placeholder="Last name is required"></asp:TextBox>
<asp:RequiredFieldValidator ID="rftLastName"
runat="server" ErrorMessage="Required Field" ControlToValidate="tLastName" Display="Dynamic"
ValidationGroup="ValGroupNewStake"></asp:RequiredFieldValidator>
</div>
<div class="form-group">
<label class="control-label">E-Mail:</label>
<asp:TextBox class="form-control" ID="tEmail" runat="server" AutoComplete="off" placeholder="Email must contain #expeditors.com"></asp:TextBox>
<asp:RequiredFieldValidator ID="rftEmail" runat="server" ControlToValidate="tEmail" Display="Dynamic"
ValidationGroup="ValGroupNewStake"
ErrorMessage="Required Field">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rftEmailAt" runat="server" ControlToValidate="tEmail" Display="Dynamic"
ErrorMessage="Invalid Email, must contain #"
ValidationGroup="ValGroupNewStake"
ValidationExpression="^\w+[\w-\.]*\#\w+((-\w+)|(\w*))\.[a-z]{2,3}$">
</asp:RegularExpressionValidator>
<asp:RegularExpressionValidator ID="rftEmailDomaain" runat="server" ControlToValidate="tEmail" Display="Dynamic"
ErrorMessage="Invalid Email, must be an #abc.com domain"
ValidationGroup="ValGroupNewStake"
ValidationExpression="^.+#[Aa][Bb][Cc][.][Cc][Oo][Mm]$">
</asp:RegularExpressionValidator>
</div>
</div>
<div class="modal-footer">
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-success btn-sm" id="cmdOk_AddSholder" runat="server" onserverclick="cmdOk_AddSholder_ServerClick" ValidationGroup="ValGroupNewStake" causesvalidation="false">Ok</button>
<button type="button" class="btn btn-danger btn-sm" id="cmdCancel_AddSholder" runat="server" data-dismiss="modal" onserverclick="cmdCancel_AddSholder_ServerClick">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmdOk_AddSholder" EventName="serverclick" />
</Triggers>
</asp:UpdatePanel>
I've put together a very simplified example of how my application is doing this. The Modal is just an ascx control and does not have an updatepanel. It's actually just a control becoming visible but we use CSS and JavaScript to make it a modal. The same logic should still apply as I've made this sample from a functioning modal.
Modal.ascx
Validators have ValidationGroup and are disabled. Button is also assigned to ValidationGroup:
<div id="approvalModal" style="display: none;">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Enabled="false"
ControlToValidate="TextBox1" ValidationGroup="testValidationgGroup" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="testValidationgGroup" />
</div>
Modal.ascx.vb
Enable the validator in a property:
Partial Class Modal
Inherits System.Web.UI.UserControl
Public WriteOnly Property Enable() As Boolean
Set(value As Boolean)
RequiredFieldValidator1.Enabled = value
End Set
End Property
End Class
PageWithModal.aspx (note: uses jQuery)
<script>
function setupTestModal() {
var modal = $('#approvalModal');
if (modal.css('display') == 'none') {
modal.show();
}
}
</script>
<asp:Button ID="ShowModal" runat="server" Text="Show Modal" OnClick="ShowModal_Click" />
<uc1:Modal runat="server" ID="testModal" />
PageWithModal.aspx.vb
Notice that when you click the ShowModal button, the validation does NOT fire. However, when the modal is visible, the Validator has been enabled.
Protected Sub ShowModal_Click(sender As Object, e As EventArgs)
testModal.Enable = True
Dim script = String.Concat("setupTestModal();")
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType(), "Popup", script, True)
End Sub

Resources