I am wondering why this, submitting on pressing enter, is only working on ie and not on google chrome...
This is the code I use actually :
<div class="TxtBox">
<asp:Panel ID="lepanel" runat="server" DefaultButton="Connect">
<asp:TextBox ID="TxtUserLogin" runat="server" TabIndex="1" Text="login" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="TxtUserLogin"></asp:RequiredFieldValidator>
<asp:TextBox ID="UserPass" runat="server" TabIndex="2" Text="password" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="UserPass"></asp:RequiredFieldValidator>
<asp:LinkButton ID="Connect" runat="server" OnClick="Connect_Click" TabIndex="3">connect</asp:LinkButton>
</asp:Panel>
<asp:Label ID="MsgError" runat="server" />
<div class="ForgottenPass">
forgotten password ?
</div>
<div class="RememberMe">
<asp:CheckBox runat="server" ID="chkBoxRemember" />
stay signed in
</div>
</div>
A LinkButton renders as a HTML anchor tag.
HTML anchor tags do not submit HTML forms. Therefore when you click Enter, this is not actioning any submit button.
A Button renders as HTML <input type="submit" />
An ImageButton renders as HTML <input type="image" />
These elements will both action your form.
Therefore changing LinkButton to Button or ImageButton is the best solution.
Using a LinkButton is also bad for users who do not have javascript enabled.
This is a known issue, when you add as default a link button (actually a link) and not a real button then there is a case that is not trigger properly.
So if you change it to real button you make it work.
Related
I have used a Requiredfieldvalidator to validate a text field however when I click on button the page gets posted back even if validation fails. What am i doing wrong? Below is my code.
<div id="addFactDiv" style="display:none;">
<asp:TextBox ID="inputFact" Height="50px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter a fact"></asp:TextBox>
<asp:requiredfieldvalidator CssClass="validator" Display="Dynamic" ID="Requiredfieldvalidator5" ControlToValidate="inputFact" ValidationGroup="ValidateFact" ErrorMessage="Please Enter a fact" runat="server"/>
<input type="button" Class="cancel" value="Cancel" OnClick="hideInput('addFactDiv');" />
<asp:Button ID="Submit_Fact" CssClass="submit" runat="server" CausesValidation="true" ValidationGroup="ValidateFact" Text="Submit" OnClick="Submit_Fact_Click"/>
</div>
EDIT
I had some commented out fields as well on the page causing the two errors I have mentioned in comments. When I removed those fields it started working fine. However I am not sure why.. Do commented out fields also get rendered on the page the same way as others?
I tried on my sample application and found below error,
WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).
Later I found that we need to add below key in .config file, which fixed the issue. (I am not sure why!)
Ref: Link
My aspx code looks like below,
<form id="form1" runat="server">
<div>
<div id="addFactDiv" style="float: right">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</div>
<p>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="test" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" ValidationGroup="test"></asp:RequiredFieldValidator>
</p>
</form>
Hope this might help!!
I have a page having multiple buttons and search functionality.I have placed one button and textbox in a panel.After writing seach text if I hit Enter,it works well for all the browsers on local, but for live application this is not working in IE.
The html is:
<asp:Panel ID="pnlSearch" runat="server" CssClass="search" DefaultButton="btnSearch">
<h2>
Explore QualityStocks without logging in</h2>
<asp:TextBox ID="txtSearch" CssClass="txt" runat="server" ToolTip="Stock Ticker" ></asp:TextBox>
<asp:Button TabIndex="0" ID="btnSearch" runat="server" ClientIDMode="Static" CssClass="btn" OnClick="btnSearch_Click" />
</asp:Panel>
What am I missing to do?
Thanks in advance,
Priya
I am trying to set default button for asp panel. Instead of asp button I am using button control with type="submit". I am getting error: "The DefaultButton of 'pnlSSN' must be the ID of a control of type IButtonControl.”.
This is the code I have:
<div class="input-append" id="divSSN"> <asp:Panel ID="pnlSSN"
runat="server" DefaultButton="btnSSN">
<asp:TextBox ID="txtSSN" runat="server" CssClass="span8" Width="200px"
placeholder="Enter valid Social Security Number">
ValidationGroup="validationSSN" />
<button runat="server" id="btnSSN"
onserverclick="btnSSN_Click" causesvalidation="true"
ValidationGroup="validationSSN" class="btn"
type="submit">Search</button> </asp:Panel> </div>
I also tried setting both pnlSSN.DefaultButton = btnSSN.ClientID; and pnlSSN.DefaultButton = btnSSN.ID; but I am getting the same error.
DefaultButton must be ASP.Net button server control instead of html Button
<asp:Panel runat="server" ID="pnlSSN" DefaultButton="btnSSN">
...
<asp:Button runat="server" ID="btnSSN" OnClick="btnSSN_Click" />
</asp:Panel>
Besides, your asp:TextBox tag is not well-formatted. Remove > at the end of Number">
On my aspx page I have two fieldsets, each wrapped with an <asp:Panel DefaultButton="..."> that have their own <input type="submit"> buttons. Here's an abbreviated version...
<div id="content">...</div>
<asp:Panel runat="server" id="formPanel1" DefaultButton="form1SubmitButton">
<fieldset>
<asp:TextBox runat="server" id="textbox1"/>
<asp:TextBox runat="server" id="textbox2"/>
<asp:Button runat="server" id="form1SubmitButton" OnClick="form1SubmitButton_OnClick"/>
</fieldset>
</asp:Panel>
<asp:Panel runat="server" id="formPanel2" DefaultButton="form2SubmitButton">
<fieldset>
<asp:TextBox runat="server" id="textbox3"/>
<asp:TextBox runat="server" id="textbox4"/>
<asp:Button runat="server" id="form2SubmitButton" OnClick="form2SubmitButton_OnClick"/>
</fieldset>
</asp:Panel>
Only the last submit button form2SubmitButton will postback, the other button does nothing when clicked. I have simplified the code above but I should mention that each form, Panel included, is kept in a separate user control that is registered on the aspx.
UPDATE: After some more research I've figured out that the submits are not working because of validators on the another fieldset on the master page. That fieldset is for signing into the site, so it is needed. Thoughts?
As PCasagrande mentioned, make sure your validation groups match the default button and all validators. Specially for your logging part.
Example:
<asp:Panel ID="pnlUpdateInfo" runat="server" DefaultButton="btnUpdateInfo">
<ASP:TEXTBOX id="txtZip" runat="server"></ASP:TEXTBOX>
<asp:RequiredFieldValidator id="reqvalZipSignUp" runat="server"
ControlToValidate="txtZip" ValidationGroup="btnUpdateInfo" />
<asp:Button ID="btnUpdateInfo" runat="server" ValidationGroup="btnUpdateInfo" />
</asp:Panel>
Turns out it has to do with HTML5 constraint validation. I figured this out because in chrome, from the console, I was getting the error An invalid form control with name='...' is not focusable. This led me to this post. I added the html5 attribute formnovalidate="formnovalidate" to the submit buttons and everything works just fine (*tested in chrome v20.0.1132.57, firefox v14.0.1, IE9 v9.0.8112).
So to recap, here's the answer...
<asp:Button runat="server" id="submit1" OnClick="submit1_OnClick" text="Submit" formnovalidate="formnovalidate"/>
I have a textbox and I have set required validationcontrol on it on click of a button.
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" runat="server" ControlToValidate="name" ErrorMessage="Name is required" Display="Dynamic" />
</td>
but the problem is when I am clicking on modify shared webpart and when I click on APPLY or OK button it is not saving as my form is empty . and I can't put
CausesValidation="false" on that button as this button is by default in sharepoint.
Any idea how to resolve this...?
You can use the ValidationGroup property to group all the Validators and validation fields together.
Yes using the ValidationGroup tag will help to relate the controls in a single form and will tell the submit button which fields are associated. Also make sure you have a ValidationSummary control on the page with the same ValidationGroup value. Also consider adding an InitialValue="" onto the TextBox control.
<asp:ValidationSummary ID="vs1" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" runat="server" ValidationGroup="Form" HeaderText="There were problems with your submission:" />
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" ValidationGroup="Form" runat="server" ControlToValidate="name" InitialValue="" ErrorMessage="Name is required" Display="Dynamic" />
<asp:LinkButton ID="lnkSubmit" Text="Submit" OnClick="lnkSubmit_Click" ValidationGroup="Form" runat="server"></asp:LinkButton>