How to fix issue with required field validator - asp.net

I inserted a required field validator in my inserttemplate of my listview. The validator is suppose to check if a value was selected in the listbox when a user clicks insert. It does what is suppose to do however, I have a search button outside the listview that displays the listview columns and when that is clicked the required field validator is triggered. I only want it to trigger when the insert button is clicked within the listview. Is this possible?
Search Button located in ContentTemplate
<div style="padding-top: 5em; text-align: center; margin-left: auto; margin-right: auto; left: 0; right: 0; width:100%">
<b style="padding-right: .5em">FormSection </b>
<asp:TextBox ID="SectionSearchBox" runat="server"></asp:TextBox>
<b style="padding-left: 1em; padding-right: .5em">SubSection</b>
<asp:TextBox ID="SubSectionSearchBox" runat="server"></asp:TextBox>
<b style="padding-left: 1em; padding-right: .5em">Section Item</b>
<asp:TextBox ID="SectionItemSearchBox" runat="server"></asp:TextBox>
<asp:Button ID="SearchButton" Height="30px" runat="server" Text="Search" OnClick="SearchButton_Click" />
</div>
Required Field Validator located in content template in the listview's insert template
<span style="color:red">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required Field!" ControlToValidate="formsection"></asp:RequiredFieldValidator>
</span>
<div style="height: auto; width: 250px; overflow: auto; border: solid; border-color: ActiveBorder" >
<asp:ListBox ID="formsection" runat="server" DataSourceID="FormSectionDataSource" DataTextField="FormSection" DataValueField="FormSectionID" AppendDataBoundItems="True" SelectedValue='<%# Bind("FormSectionID") %>' Height="150px">
<asp:ListItem Selected="True" Value=""><- please select -></asp:ListItem>
</asp:ListBox>
</div>

I figured it out, in the code behind I used.
SearchButton.CausesValidation = false;
When the button is clicked it does not trigger the validation.

Related

ASP NET LinkButton - Inner Controls Removed

We have the follow repeater construct on our home page:
<asp:Repeater runat="server" ID="repShortcuts" OnItemDataBound="repShortcuts_ItemDataBound">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkShortcut" PostBackUrl='<%# Eval("LinkWithTab") %>' Text="" ViewStateMode="Enabled" Style="text-decoration: none;">
<div style="margin-left: 2px; margin-right: 2px; height: 90px; display: inline-block; white-space: normal; text-align: center; vertical-align: top;">
<asp:Image
runat="server"
ID="imgShortcut"
ImageUrl='<%# String.Format("./Icons/{0}{1}",Session["DetailsBoxTextColour"].ToString().ToLower() == "black" ? "d" : "", Eval("ParentIcon")) %>'
CssClass="MenuImage"
Style="margin-bottom: 0px;"
/>
<asp:Label
runat="server"
ID="lblShortcut"
Text='<%# Eval("DisplayName") %>'
CssClass="MenuText"
Style="font-size: small; overflow: hidden; width: 110px; white-space: pre-line; text-wrap: normal; display: inline-block;"
></asp:Label>
</div>
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmptyData" runat="server" CssClass="DetailsBoxSettingLabel MarginTop5" Text="You currently have no shortcuts." Visible="false" />
</FooterTemplate>
</asp:Repeater>
When viewing the page (GET):
On server A (live) the inner controls are rendered as expected (this is an image and some text). Also works on all our dev machines.
On server B (uat) and some user machines which have the application installed, the inner controls are removed and we are just left with the anchor tag for the linkbutton.
This seems to be related to Microsoft Connect issue 718810 which is nowhere to be found now. Completely lost as to what's going on here. Same code, same server setup essentially.

IE bug asp:textbox after delete and tab changes the input display to absolute 0,0

So I have the weirdest bug, I have a form with several asp:textbox controls if I write the code and make a tab nothing happens everything stays normal but if for any reason I delete some of the text and then change control, the textbox background moves to the upper left corner of the screen, while the text I entered stays on the same place... I'm trying to fix it making the cell that contains the textbox position: relative but now the displays goes over the text and doesn't let me see what I wrote.
Here is my code:
<table id="tabla-form1">
<tr>
<td class="tabla-form1-cell">
<span style="float: left;">Nombre</span>
<asp:RequiredFieldValidator ID="validNombre" runat="server" ControlToValidate="txtNombre" ErrorMessage="Necesitas ingresar un nombre" Text="*" ForeColor="Red" />
<asp:TextBox id="txtNombre" runat="server" CausesValidation="true" />
</td>
</tr>
<tr>
<td class="tabla-form1-cell">
<span style="float: left;">Apellido</span>
<asp:RequiredFieldValidator ID="validApellido" runat="server" ControlToValidate="txtApellido" ErrorMessage="Necesitas ingresar un apellido" Text="*" ForeColor="Red" />
<asp:TextBox ID="txtApellido" runat="server" CausesValidation="true" />
</td>
</tr>
<tr>
<td class="tabla-form1-cell">
<span style="float: left;">Fecha de nacimiento</span>
<asp:RequiredFieldValidator ID="validNac" runat="server" ControlToValidate="txtNac" ErrorMessage="Necesitas ingresar una fecha" Text="*" ForeColor="Red" />
<asp:TextBox ID="txtNac" runat="server" CssClass="fecha" />
</td>
</tr>
</table>
This is my CSS:
input[type='text'] {
width: 160px;
height: 20px;
border-color: #bdbdbd;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-style: solid;
border-width: 2px;
color: #454545;
z-index: 10;
behavior: url("js/PIE.htc");
}
This happens to me both with textboxes with validation and without it, and it only happens in IE, firefox and chrome make it work just fine.
I appreciate any help.
Thanks
As adaam said, in your CSS, you have:
behavior: url("js/PIE.htc");
You should review or remove the link to PIE.htc.
More information on Progressive Internet Explorer (PIE):
Documentation on PIE
Getting started with PIE

How do I get asp:Label to take up space before having text assigned

I have 2 buttons that need to be on the right hand side of a form and have a label on the right. The problem I am running into is that once the action has been performed, the label will read "successfully ...." or "error couldn't..." and it screws up my layout. when the form first appears it screws up my button layouts because the label is empty, then when the action has been performed, my label gets populated with text and then pushes my buttons into the right place. Is there a way to to keep my buttons in place?
Here is my layout:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="dropDownList" style="position: relative;" runat="server">
<label>
Select New File:
</label>
<asp:DropDownList runat="server" ID="ddlCaseFiles" DataSourceID="dsMyCaseFiles" DataTextField="Display"
DataValueField="FileID" OnPreRender="ddl_PreRender" Width="524px" OnSelectedIndexChanged="ddlCaseFiles_SelectedIndexChanged" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlCaseFiles"
ToolTip="Casefile Required" InitialValue="-1" Text="*" Display="Dynamic" />
<ajaxToolkit:ListSearchExtender ID="ddlExtCaseFiles" runat="server" PromptCssClass="ListSearchExtenderPrompt"
TargetControlID="ddlCaseFiles" BehaviorID="ddlExtCaseFiles" Enabled="True" />
<br />
/////////////////////////area of interest
<asp:Button ID="btnCancel" runat="server" Text="Cancel" Style="position: relative;
float: left; margin-left: 450px;" OnClientClick="parent.$.fancybox.close();" />
<asp:Button ID="btnMoveCaseFile" runat="server" Text="" Style="position: relative;
float: right; margin-right: 63px; margin-left: -45px; top: 0px; left: 0px; width: 98px;"
OnClick="btnMoveCaseFile_Click" />
<asp:Label runat="server" ID="lblStatus"></asp:Label>
<br />
///////////////////////////////////////////////
</div>
</ContentTemplate>
I'm trying to get the buttons to light up under the dropdownlist and have the Label show on the same line as the buttons but on the left. (this code has the label on a new line because I gave up)
You can set your controls in table cells , and fix the width of cells.
Nota : you can fix width with css class.
<table>
<tr>
<td>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" Style="position: relative; float: left; margin-left: 450px;" OnClientClick="parent.$.fancybox.close();" />
</td>
<td>
<asp:Button ID="btnMoveCaseFile" runat="server" Text="" Style="position: relative; float: right; margin-right: 63px; margin-left: -45px; top: 0px; left: 0px; width: 98px;"
OnClick="btnMoveCaseFile_Click" />
</td>
<td>
<asp:Label runat="server" ID="lblStatus"></asp:Label>
</td>
</tr>
</table>

Multiple ASP modal popups on one page

We have a working modal popup on an asp.net page, and need to add another one. A linkbutton opens the first one.
But if we try adding code for another linkbutton to open a second popup, which will use another mp extender control, neither one of them work. If we then remove the second popup and extender code, it works again.
I posted this question before but got an answer about using them in a gridview, which is not what is going on. This issue is not that complicated, just the fact that we can't get two separate popups working on a page. Are there any bugs or anything that would be preventing this from working?
The code below is for the working popup. It seems logical that if we add code that works to a page and give the controls new names, it should work as well, right? Anyway, a little help?
<!--modal popup extender-->
<ajax:ModalPopupExtender ID="mpe1" runat="server"
DropShadow="false"
TargetControlID="btn1"
PopupControlID="mp1"
BehaviorID="ModalPopBehavior"
CancelControlID="btnCancel">
</ajax:ModalPopupExtender>
<!--modal panel-->
<asp:Panel ID="mp1" runat="server" EnableViewState="true" Visible="False" Width="290px" height="140px"
BorderWidth="4px" BorderStyle="Ridge" BorderColor="Control" style="display:none;" >
<asp:Table ID="Table1" runat="server" BorderStyle="None" Width="290px" Height="140px" BackColor="#ffffee">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell ID="TableCell1" runat="server">
<asp:Label ID="lbl1" runat="server" CssClass="PanelLabel"
Style="left: 60px; position: absolute; top: 4px" Text="label1"
ForeColor="#0000C0" />
<asp:Label ID="lbl2" runat="server" CssClass="StdLabel"
Style="left: 6px; position: absolute; top: 30px" Text="label2" />
<asp:TextBox ID="txt1" runat="server" CssClass="StdTextbox"
Style="left: 6px; position: absolute; top: 44px" Width="120px" />
<asp:Label ID="lbl3" runat="server" CssClass="StdLabel"
Style="left: 160px; position: absolute; top: 30px"
Text="label3" />
<asp:TextBox ID="txt2" runat="server" CssClass="StdTextbox"
Style="left: 160px; position: absolute; top: 44px" Width="120px" />
<asp:Button ID="btnOK" runat="server"
Style="font-family: Tahoma; font-size: 11px; color: Navy; left: 60px;
position: absolute; top: 86px" Text="OK" Width="90px" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" Width="50px"
style="font-family: Tahoma; font-size: 11px; color: Navy; top: 86px; left: 170px;
position:absolute;"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table></asp:Panel>
In the page there is also the hidden button for the popup. it looks like this:
<!--hidden button for modal popup -->
<asp:Button ID="btn1" visible="true" runat="server" Style="display: none" Enabled="false" />
ok so the problem was that the behaviorID property for each extender had to be unique. Once I set the behaviorID to the same name as the ID in each extender, they all work. Of course all other controls on all popup objects themselves must also be unique.

ms ajax hover extender error "An extender can't be in a different UpdatePanel than the control it extends"

It is obvious that the control and the extender are in the same update panel. Yet, a "An extender can't be in a different UpdatePanel than the control it extends" error occurs.
NOTE: The user control is declared within an UpdatePanel on the page using it. That makes the UpdatePanel in the user control "nested".
The following code is in the Asp.Net UserControl:
<asp:TemplateField HeaderStyle-Width="0px">
<ItemTemplate>
<asp:UpdatePanel ID="hoverMenuUpdatePanel" runat="server">
<ContentTemplate>
<ajaxtoolkit:HoverMenuExtender ID="extensionActionHoverMenuExtender" runat="server"
PopupControlID="extensionActionHoverMenu" PopupPosition="Left" HoverCssClass="popupHover"
TargetControlID="extensionActionHoverMenu" OffsetX="5" PopDelay="50" />
<asp:Panel ID="extensionActionHoverMenu" runat="server" CssClass="modalDialogPanel"
Style="display: none; height: 200px; width: 300px; padding: 5px;">
<div style="border-color: #3A362C; padding: 2px; border-right-style: solid; border-right-width: thin;
float: left;">
<div class="title">
Reserve Extension: &nbsp
<asp:Label ID="extensionToReserveLabel" runat="server" Text='<%# Eval("ConsolidatedPhoneExtensionPK") %>' />
</div>
<div id="userType" style="border-style: solid; border-width: 1px; padding: 5px; height: 80px;
width: 200px; background-color: #E2DDBA; margin-bottom: 8px;">
User Type:
<asp:RadioButtonList ID="reservedUserTypeRadioButtonList" runat="server">
<asp:ListItem Selected="true" Text="999/988" Value="Employee" />
<asp:ListItem Text="Other" Value="Other" />
</asp:RadioButtonList>
</div>
<div>
Employee No:<asp:TextBox ID="reserveEmployeeNo" runat="server" OnTextChanged="reserveEmployeeNo_TextChanged"
AutoPostBack="true" />
<asp:Label ID="employeeNameDisplayLabel" runat="server" />
<asp:Label ID="reserveUserMessageAreaLabel" runat="server" />
</div>
</div>
<div>
<div>
<asp:Button ID="selectButton" runat="server" Text="View" CommandName="Select" Width="75px" />
</div>
<div>
<asp:Button ID="reserveButton" runat="server" Text="Reserve" CommandName="Reserve"
CommandArgument='<%# Eval("ConsolidatedPhoneExtensionPK") %>' Width="75px" />
</div>
</div>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="reserveEmployeeNo" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
Create a panel with an ID of "popup" (it can be anthing you like though). In this panel place any buttons or what ever you want, this will be your popup menu. Set your PopupControlID to "popup".
Your TargetControlID should be the ID of the panel you want the manu to popup in (extensionActionHoverMenu?).
PopupControlID and TargetControlID are the same. Your TargetControlID should be some other form element.
HoverMenu Sample:
TargetControlID - The control that the extender is targeting. When
the mouse cursor is over this control,
the hover menu popup will be
displayed.
PopupControlID - The ID of the control to display when mouse is over
the target control. In this case, it's
just a simple panel with two links:
Sometimes it's not about the updatepanel but about other items of the toolkit.
I got this message while using the FilteredTextBoxExtender. The control defined int the TargetControlID was in a different updatepanel.

Resources