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.
Related
I have an ASPX based solution that is running under .NET 4.8 and IIS 6.2. We have a login screen.
When a user enters their username and password, then hits enter or clicks enter, they should be logged in. The problem we are having is, if a user clicks the login button everything is fine but if they hit enter, the page seems to refresh but not postback.
Some history...We had this issue years ago when we were hosted under GoDaddy. There was some IIS setting that they changed at some point that broke our app and caused this. They wouldn't undo this as the setting (they wouldn't tell me what setting) would apply to others on the same IIS. We moved to a new host and now have our own IIS running on its on box. We have not had this issue for years and now recently it has cropped back up again. When I test this code locally under IIS Express via Visual Studio, we do not have the problem. When I publish to our server, the problem arises.
I am pulling my hair out on this one.
EDIT 2020-10-09 - Added markup
<form id="Form1" runat="server">
<div class="container" id="container" runat="server">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<p style="text-align: center;">
<img src="./images/logo160x300.png" />
</p>
<h2>
Sign In</h2>
<div id="errorPanel" runat="server" style="display: none;">
<asp:label ID="lblAuthenticationFailure" runat="server" Text="Login failed. Please check your username and password."
Visible="True" Font-Bold="True" ForeColor="#CC0000"></asp:label>
<br />
<br />
</div>
<label for="txtUser">
Email</label>
<asp:TextBox ID="txtUser" runat="server" placeholder="Email" type="email" class="form-control"
required autofocus AutoComplete="username"></asp:TextBox>
<br />
<label for="txtPassword">
Password</label>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" placeholder="Password"
class="form-control" required AutoComplete="current-password"></asp:TextBox>
<div class="text-right small">
Forgot your password?</div>
<br />
<asp:Button ID="butLogin" runat="server" Text="Sign in" type="submit" class="btn btn-lg btn-primary btn-block" />
<br />
<div class="text-center">
New? Need an Account?<br />
</div>
<a class="btn btn-default btn-lg btn-block" href="createlogin.aspx" role="button">Create
an account</a>
<br />
</div>
</div>
</div>
</form>
In your form tag set the defaultButton to the login button.
<form id="form1" runat="server" defaultbutton="IdOfSubmitbutton">
You can set the default postback button on PageLoad by
Page.Form.DefaultButton = myButton;
Make sure you do a search. This has probably been answered.
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.
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
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
I have an online banking login that I'm trying to take from an old client site and put on their new site. If I copy the form and paste it into my new site, it just reloads the page when submitted. I've tried to change it to an asp.net form using the appropriate and other applicable tags with the same result.
If I take the form and put it in a simple index.html file, it submits and takes me to the correct external site.
I was unable to set the ID & values with the asp.net form and that may be one of the issues.
Any help is appreciated.
Here is the HTML form version that works in .html page that needs to work in .aspx page:
<form action="some external site" method="POST" autocomplete="OFF" target="_top">
<input type="hidden" name="sssid" value="my value">
<input type="hidden" name="iid" value="another value">
<div class="field-container">
<label for="aid" id="aid-label">Access ID</label>
<input name="aid" id="aid" type="text" size="8" onFocus="toggle_label(this, 'focus');" onBlur="toggle_label(this,'blur');" />
</div>
<div class="field-container">
<label for="passcode" id="passcode-label">Passcode</label>
<input name="passcode" id="passcode" type="password" size="8" onFocus="toggle_label(this, 'focus');" onBlur="toggle_label(this,'blur');"/>
</div>
<div class="form-row">
<input type="submit" name="Submit" value="Go" class="button">
</div>
</form>
Here is my asp.net form version that I tried:
<form action="some external site" method="POST" autocomplete="OFF" target="_top">
<input type="hidden" name="sssid" value="some value">
<input type="hidden" name="iid" value="another value">
<asp:TextBox runat="server" ID="sssid" CssClass="form-control" type="hidden" ClientIDMode="Static"></asp:TextBox>
<asp:TextBox runat="server" ID="iid" CssClass="form-control" type="hidden" ClientIDMode="Static"></asp:TextBox>
<div class="form-group">
<asp:Label runat="server" id="lblAccessID"></asp:Label>
<asp:TextBox runat="server" ID="txtAccessID" CssClass="form-control"> </asp:TextBox>
</div>
<div class="form-group">
<asp:Label runat="server" id="lblPassCode"></asp:Label>
<asp:TextBox runat="server" ID="txtPasscode" CssClass="form-control" TextMode="Password"></asp:TextBox>
</div>
<button type="submit" class="btn btn-blue">GO
<img src="/Content/img/icon-sm-arrow.png" alt="" />
</button>
</form>
My asp.net form code behind:
protected void Page_Load(object sender, EventArgs e)
{
txtAccessID.Attributes.Add("placeholder", "Access ID");
txtPasscode.Attributes.Add("placeholder", "Passcode");
}
I had to use the following to post this correctly:
<asp:LinkButton runat="server" ID="btnSubmit" CssClass="btn btn-blue" PostBackUrl="urlhere" Text='GO <img src="/Content/img/icon-sm-arrow.png" alt="" />' />
set PostBackUrl property of Button control => https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.postbackurl(v=vs.110).aspx
the reason webforms always posting it 2 itself may be due to their __doPostBack script.