the problem I have is that I have a form (asp.net form) and some of the fields (most of them) have RequiredFieldValidator. Now I also set SetFocusOnError="true" on all of them and it works fine for all but dropdowns. Let me define fine: after clicking on the Submit button while one of the fields is left blank, browser scrolls up to the empty field. In case of dropdowns the error message is indeed displayed properly next to the field however browser will not scroll up the screen to the field. I've read similar questions on stack overflow so far and they all come to "use JavaScript for this", but my problem is that I want to use asp.net property for this. If it's there it's supposed to work, right? Unless I do it wrong. Here comes the code for one of the working fields:
<div class ="row">
<div class="three columns medium" align="right">
<label>Email *</label>
</div>
<div class="three columns large">
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
</div>
<div class="six columns large">
<asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email"
ErrorMessage="Please provide us your email address" forecolor="Red" SetFocusOnError="true" runat="server" /><br />
<asp:RegularExpressionValidator ID="EmailFormat" ControlToValidate="Email"
ErrorMessage="Please provide us valid e-mail address" ValidationExpression="^[^\s#]+#[^\s#]+$" forecolor="Red" runat="server" />
</div>
</div>
and here's a sample of not working focus:
<div class ="three columns medium" align="right">
<asp:DropDownList class="dropdown expand" ID="Location" runat="server">
<asp:ListItem
Enabled="True"
Text="Please choose the office location... *"
Value=""
/>
<asp:ListItem
Enabled="True"
Text="City1"
Value="City1"
/>
<asp:ListItem
Enabled="True"
Text="City2"
Value="City2"
/>
<asp:ListItem
Enabled="True"
Text="City3"
Value="City3"
/>
</asp:DropDownList>
</div>
<div class ="six columns large">
<asp:RequiredFieldValidator ID="LocationRequired" ControlToValidate="Location"
ErrorMessage="Please select the office location" forecolor="Red" SetFocusOnError="true" runat="server" />
</div>
<div class ="three columns large"></div>
Is my code wrong or am I expecting the wrong thing from it?
Set the ValidationGroup property of the each of the controls involved in this, such as the Drop Down List, Button, Required Field Validator etc as
ValidationGroup="Selection"
I afraid that 3rd party scripts like jqTransform break something in asp.net script that is setting focus on error controls. Try to remove 3rd party scripts and check. If they were cause then you need to invent something with java script
Related
I am creating a new Web UserControl in my ASP.NET Web Form project (using VB.NET). Normally, I could add custom attributes to my UserControl like in the solution for this question.
However, when it comes to the properties of the child controls, the name of each attribute becomes quite long as I tried to include the control name in it.
For example, I have simple user control like this:
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb"
Inherits="Web.MyControl" %>
<asp:Panel ID="pnl_Filter" runat="server">
<div class="d-flex row">
<div class="col-1">
<asp:Label ID="lbl_Subject" runat="server" Text="Subject" Font-Bold="true" />
</div>
<div class="col-5">
<asp:DropDownList ID="ddl_Subject" runat="server"
DataSourceID="ods_Subject"
DataTextField="subject_name"
DataValueField="subject_id">
</asp:DropDownList>
<asp:ObjectDataSource ID="ods_Subject" runat="server"
TypeName="Web.SubjectManager"
SelectMethod="GetSubjectList" />
</div>
....
</div>
</asp:Panel>
I wonder if I could create custom inner tag inside my UserControl so, when I place it in parent page, I could do something like this:
<uc:MyControl ID="mc_filter" runat="server">
<LabelProperties Text="Subject" Font-Bold="true" />
<DropdownProperties DataSourceID="ods_Subject"
DataTextField="subject_name"
DataValueField="subject_id" />
</uc:MyControl>
This is not a pretty application by any stretch. It's only meant for a select few to use in the office and does not require street appeal. With that said...
I have a gridview with the following template column:
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblAction" runat="server" Text='<%#(Eval("Action"))%>'
ToolTip="Action to be Taken"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAction" runat="server"
TextMode="MultiLine" Width="450px" Height="100px" ValidationGroup="UpdateFU"
Text='<%#Eval("Action")%>'
CssClass="RequiredText" ToolTip="Follow-Up Action">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_txtAction" runat="server"
ControlToValidate="txtAction" ErrorMessage="FollowUp Action is Required"
Text="*" ValidationGroup="UpdateFU">
</asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAction" runat="server"
TextMode="MultiLine" Width="250px"
ValidationGroup="UpdateFU"
CssClass="RequiredText"
ToolTip="Follow-Up Action">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_txtAction" runat="server"
ControlToValidate="txtAction" ErrorMessage="FollowUp Action is Required"
Text="*" ValidationGroup="AddFU">
</asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
For the example that is causing me trouble, the data in the field that is bound to this column is: **Testing with a link. Google**
The label in the ItemTemplate displays as I expect it to. The regular text is not hyperlinked and the hyperlink text is. Please see the included image:
ItemTemplate
When my row is in Edit mode, it also displays in the TextBox as I would suspect. Please see the included image: EditItemTemplate
When I attempt to Save or Cancel the record, the gridview does not recognize that the command button was clicked. It just sits there. If I remove the text that references the tag (leaving from my example, **Testing with a link.**), it works beautifully. The only problem being that I can't save any text in the textbox with my link.
Any help is greatly appreciated.
I think you are using UpdatePanel around your GridView. That is why you are missing exceptions if you are not checking the browser console. And that exception could very well be A potentially dangerous Request.Form value was detected from the client
Fixes for that here
A potentially dangerous Request.Form value was detected from the client
A potentially dangerous Request.Form value was detected from the client
https://www.codeproject.com/Tips/297679/A-potentially-dangerous-Request-Form-value-was-det
https://www.aspsnippets.com/Articles/ASPNet-Error-A-potentially-dangerous-RequestForm-value-was-detected-from-the-client.aspx
TextBox is Enabled="false", which is why the tooltip is not showing on TextBox.
What should I do to show the ToolTip without changing state of TextBox?
<asp:TextBox ID="txtDescription" data-original-title="Description" Enabled="false" runat="server" Class="txtDescription form-control tooltips"></asp:TextBox>
I use ReadOnly="true" and it's work.
<asp:TextBox ID="txtDescription" data-original-title="Description" ReadOnly="true" runat="server" Class="txtDescription form-control tooltips"></asp:TextBox>
I'm fairly new in asp.net, and I am more proficient at building html/php websites.I am trying to add twitter bootstrap to my textboxes. My current textbox shows:
<asp:TextBox ID="UserName" runat="server" Width="250px" TabIndex="1"></asp:TextBox>
And the input that I designed using html is:
<input type="text" class="form-control input-lg" placeholder="Username">
How do I put all the classes of my textbox to my asp textbox, and would it take effect in a similar way html elements work?
You can put these classes in asp textbox using CssClass as follows
<asp:TextBox ID="UserName" runat="server" CssClass="form-control input-lg"
Width="250px" TabIndex="1"></asp:TextBox>
Basically when you create a control asp control it render as a html control on the browser.
So in the browser you will see the same.
There may be difference in the id and the name of the control. As they are generated depending on the controls like master page and user controls.
Though you have different ClientIdMode in asp.net to overcome this issue.
MSDN for the same is http://msdn.microsoft.com/en-us/library/system.web.ui.clientidmode.aspx
<asp:TextBox ID="UserName" runat="server" CssClass="form-control input-lg"
Width="250px" TabIndex="1" placeholder="Username"></asp:TextBox>
I use a modal popup extender, i followed all the instructions on the toolkit sample page, except that i didn't set the property BackgroundCssClass.
this is what happens:
Is there a way I can get rude of it without setting the cssclass prop?
I don't need any styles.
If the answer is NO then please show me an example how to set it with a cssclass (even dummy).
Thanks in advance.
Here is the code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<div style="size: 100%; vertical-align: middle">
<asp:LinkButton ID="lnkUpload" Text="Upload" ToolTip="Upload new file" runat="server" OnClick="lnkUpload_Click" />
<cc1:ModalPopupExtender ID="lnkUpload_ModalPopupExtender" runat="server" Drag="true" PopupDragHandleControlID="pnlUploadTitle" DynamicServicePath="" PopupControlID="pnlUpload" Enabled="True" TargetControlID="lnkUpload" CancelControlID="btnCancel" />
</div>
<asp:Panel ID="pnlUploadTitle" runat="server" Visible="false">
<center>
Upload file
</center>
</asp:Panel>
<asp:Panel ID="pnlUpload" runat="server" Visible="false">
<center>
<br />
<asp:FileUpload ID="upFiles" runat="server" /><br />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<br />
</center>
</asp:Panel>
</div>
</form>
You can set the ModalPopupExtender's backgroundCssClass within the actual HTML markup.
Example from the asp.net modal popup page:
<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server"
TargetControlID="LinkButton1"
PopupControlID="Panel1"
**BackgroundCssClass="modalBackground"**
DropShadow="true"
OkControlID="OkButton"
OnOkScript="onOk()"
CancelControlID="CancelButton"
PopupDragHandleControlID="Panel3" />
I spent ages looking up a solution for the similar problem
Set your PopUpControlId to be the ClientID of the control.
It solved the problem for me.
Also read more on: Codeplex
Ha-ha, I remember more then 2 years ago in AJAX beta not setting the BackgroundCssClass property caused modal popup not to be really modal, but just popup. I remember setting a style class solved the problem. I haven't used AJAX for a long time, it's funny if similar problems still persist.
Anyway, create stylesheet class inside your ASPX page or in CSS file referenced form it and set the property value to it. Maybe, this will also help.