ASP.NET validation missing something? - asp.net

I usually don't resort to posting questions that seem simple, but this one has me stumped.
I have a text box that is a required field, and when I click submit I want to validate the text box.
Here is my code:
<asp:TextBox ID="txtName" runat="server" CssClass="textboxField" MaxLength="45"></asp:TextBox>
<asp:LinkButton ID="btnAdd" runat="server" CausesValidation="True" >Add +</asp:LinkButton>
<asp:RequiredFieldValidator ID="reqName" ControlToValidate="txtName" ErrorMessage="Name is required." runat="server" />
Everything here looks correct to me syntax wise, but for some reason I am not seeing an error message when the text box is blank and the add button is clicked. Any suggestions?
EDIT: Page directive
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPages/SiteMaster.Master" AutoEventWireup="true" CodeBehind="CodeBehind.aspx.cs" Inherits="Site.Page" %>

Related

how to work with multiple forms in one asp.net page

I hava a asp.net that I thought is going to have multiple forms.I put a asp panel and added the form to it and validators to controls everyting works.but if I try to put another panel and a form page become invalid.the reason I do this is because any attempt to postback data will trigger all validtors.I know that I can brake each form to each page.but for my design this seems silly.
what im looking for a way to have multiple forms in one page.
or have validators work only on certain situations.
or group validators to work if the button click only happen in the same panel where validators reside.
You cannot place more than one form tag in a single ASPX page. It is a limitation of ASP.Net Web Form.
However, you can fake it with ValidationGroup. For example -
<%-- Group One --%>
<asp:TextBox ID="TextBox1" runat="server"
ValidationGroup="One" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
Display="Dynamic"
ValidationGroup="One"
ControlToValidate="TextBox1"
Text="Textbox one is required." />
<asp:Button runat="server" ID="Button1"
OnClick="Button1_Click"
Text="Submit"
ValidationGroup="One" />
<hr/>
<%-- Group Two --%>
<asp:TextBox ID="TextBox2" runat="server"
ValidationGroup="Two" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server"
Display="Dynamic"
ValidationGroup="Two"
ControlToValidate="TextBox2"
Text="Textbox two is required.." />
<asp:Button runat="server" ID="Button2"
OnClick="Button2_Click"
Text="Submit"
ValidationGroup="Two" />
Note: If you want multiple form tags in a single page, you might want to look at ASP.Net MVC.

CalendarExtender from AjaxControlToolKit.Dll Doesn't 'Pop Up' When Upgrading/Updating to Latest Dll Version

I have a form that formerly used assembly version 1.0.10301.0 of the AjaxControlToolKit.Dll and when upgrading to newer versions such as 4.1.7.607, the CalendarExtender object stops working in that the calendar button no longer creates a drop down-esque selection object. Nothing has changed in my code, only the Third Party dll as it jumped from 764KB to ~6.5MB.
The issue seems to be that if there is more than one image with the same ID (I have three), this issue occurs. Source: Calendar control is not popping-up when clicked on image
Because of the dynamic way in which the actual form is created, it is impossible for me to 'hardcode' several instances of CalendarExtender in the .ascx and call them in the .cs so as to prevent this issue; eg I can only have this dateCal. Is there a way to resolve this issue that will still allow me to upgrade to the latest version of the Dll such as some sort of flag that allows for multiple instances of the same ID?
Code:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="DateTb.ascx.cs" Inherits="DateTb" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajx" %>
<asp:TextBox ID="dateTb" runat="server" Width="125px" MaxLength="1000"></asp:TextBox>
<asp:image id="dateImg" runat="server" imageurl="~/images/calendar.png" />
<ajx:CalendarExtender ID="dateCal" runat="server" PopupButtonID="dateImg" TargetControlID="dateTb"></ajx:CalendarExtender>
<asp:CompareValidator id="dateValidator" runat="server" Type="Date" Operator="DataTypeCheck" ControlToValidate="dateTb" ErrorMessage="Please enter a valid date." ValidationGroup="validate" Text="*" > </asp:CompareValidator>
<asp:RequiredFieldValidator ID="dateRequired" runat="server" ControlToValidate="dateTb" Text="*" ErrorMessage="Please enter a valid date." ValidationGroup="validate"></asp:RequiredFieldValidator>
Form Pre-DLL 'Upgrade':
Form Post-DLL 'Upgrade':

No event is firing in asp.net

In my website No button event is firing.
<asp:Button ID="Button1" Text="Add_Record" runat="server" AutoPostBack="true"
onclick="Button1_Click" />
when I write code in the event handler. It does not call.
On every page of website I am facing this issue.
<div id="eList">
<p>Enter Your Email To Sign Up<br>
For Our E-Newsletter:</p>
<asp:TextBox ID="elist_input" runat="server" Width="169px">
</asp:TextBox>
<br>
<asp:Button class="elist_submit" runat="server" Text="Search" Width="56px"
onclick="Unnamed1_Click" />
<div id="display_menu_2">
<asp:Button ID="Button1" Text="Add_Record" runat="server"
AutoPostBack="true" onclick="Button1_Click" />
Page Directive
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="HomePage.aspx.cs" Inherits="homePage" %>
Your project must have been Web application project and the CodeFile attribute is valid only in Web site project for compiled pages, change it to the CodeBehind like this.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="homePage" %>
I was not able to call the event handlers. the problem was due to the header.ascx file. In that file I used form and also a form in Master page. As Master page is inhereted to all pages and header is also. due to two form in one page event handlers were not working..

RequiredFieldValidator not working

With the following simple mark-up, I get very strange behaviour in FF and IE8. If I give the textbox focus, and tab out, nothing happens. If I give a user name value, and erase it immediately, nothing happens. However, only when I supply a user name, tab away, the erase it and tab away again, do I finally get a red star "required" mark. The summary doesn't show at all.
This is the markup I was trying with. Looks like my issue was with EnableClientScript and ValidationGroup:
<asp:Label ID="userNameLabel" runat="server"
AssociatedControlID="userNameText">
User Name:
</asp:Label>
<asp:TextBox ID="userNameText" runat="server"
Width="200px">
</asp:TextBox>
<asp:RequiredFieldValidator ID="userNameRequired" runat="server"
ControlToValidate="userNameText"
Display="Dynamic"
EnableClientScript="true"
ValidationGroup="userValidation"
ErrorMessage="User Name is always required.">
*
</asp:RequiredFieldValidator>
Are you sure EnableClientScript="true" is even needed? I think it defaults to that.

ASP.NET 3.5 :No Postback triggered for button click

I have an ASP.NET page developed in VS 2008. there is a text box and login button.Required fireld validator and Validtion Group controls are associate for validation.I wrote code for the Button click evenet handler too.But the Button click is not getting fired.There is no post back happening. Can any one tell me why ?
HTM lmarkup
<asp:TextBox ID="txtLoginPass" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" ValidationGroup="Login" />
Validators generate client side JavaScript which can prevent a postback if the required field is empty.
Is that exact code snippet? It didn't work at all - no such control as txtPassword.
Altough, this worked as expected:
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" ValidationGroup="Login" />
I'm sure that you've got that correct in your code, so the problem must be somewhere else - could please post more code surrounding this snippet?
I expect that you have AutoPostBack="True" on one of your components. If so then remove that and your onclick should work on the button.
I had this same exact problem. The RequiredFieldValidator was working as expected when the textbox was empty, but the button click wasn't causing a postback when there was text. My problem? I was using the same validationgroup name in a separate user control. So make sure all of your validationgroup names are unique.

Resources