|
-
Dec 4th, 2008, 06:03 PM
#1
Thread Starter
Frenzied Member
requirefieldvalidate control for all text boxes
Hi, I have about 20 text boxes on my form, and I want to validate each field using the requiredFieldvalidate control; however, I don't want to add that control to each text box.. it's tiring Is there a way to do that?
-
Dec 5th, 2008, 07:46 AM
#2
Re: requirefieldvalidate control for all text boxes
No.
You could make a user control called RequiredTextBox (or something) that contains a textbox and a requiredfieldvalidator.
-
Dec 5th, 2008, 07:53 AM
#3
Re: requirefieldvalidate control for all text boxes
In fact here's one I made quite sometime ago. It's pretty basic but did what I needed at the time and should give you an idea.
RequiredTextBox.ascx
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RequiredTextBox.ascx.cs" Inherits="Controls_RequiredTextBox" %>
<asp:TextBox ID="requiredTextBox1" runat="server" /><asp:RequiredFieldValidator ID="rfv1" runat="server" Text="*" ControlToValidate="requiredTextBox1" Display="Dynamic" />
RequiredTextBox.ascx.cs
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Controls_RequiredTextBox : System.Web.UI.UserControl
{
public bool Password
{
set { this.requiredTextBox1.TextMode = TextBoxMode.Password; }
}
public string ErrorText
{
set { this.rfv1.Text = value; }
}
public string ErrorMessage
{
set { this.rfv1.ErrorMessage = value; }
}
public string Text
{
get {return this.requiredTextBox1.Text; }
set { this.requiredTextBox1.Text = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
Usage:
Code:
<%@ Register TagPrefix="fishcake" TagName="RequiredTextBox" Src="~/Controls/RequiredTextBox.ascx" %>
....
<fishcake:RequiredTextBox ID="txtCompanyName" runat="server" />
Last edited by Fishcake; Dec 5th, 2008 at 09:28 AM.
-
Dec 8th, 2008, 08:59 AM
#4
Hyperactive Member
Re: requirefieldvalidate control for all text boxes
Install Ajax control toolkit, it will more help ful for u
MCP, MCTS, Microsoft MVP [Asp.Net/IIS]
For more .NET development tips visit .NET Tips
If the post is useful then please  Rate it
-
Dec 8th, 2008, 11:18 AM
#5
Re: requirefieldvalidate control for all text boxes
 Originally Posted by koolprasad2003
Install Ajax control toolkit, it will more help ful for u
Which part of the Ajax toolkit and how would vbbit use it to solve his problem?
-
Dec 9th, 2008, 02:31 AM
#6
Re: requirefieldvalidate control for all text boxes
I don't recommend installing an entire set of class libraries or a framework for the sole purpose of using one tiny feature. It's overkill. I'd go with fishguy's solution or simply have twenty requiredfieldvalidators or do it all the codebehind in one go and present the user with the result of that validation.
-
Dec 9th, 2008, 03:46 AM
#7
Re: requirefieldvalidate control for all text boxes
Excuse me!!! I'm Fishcake, Fishguy is that other fish related user.
-
Dec 9th, 2008, 02:18 PM
#8
Fanatic Member
Re: requirefieldvalidate control for all text boxes
 Originally Posted by mendhak
I don't recommend installing an entire set of class libraries or a framework for the sole purpose of using one tiny feature.
Just curious, why? AjaxControlToolkit.dll is a single library that is to be deployed with your web solution. You use only the feature that you want.
-
Dec 10th, 2008, 01:55 AM
#9
Re: requirefieldvalidate control for all text boxes
 Originally Posted by rjv_rnjn
Just curious, why? AjaxControlToolkit.dll is a single library that is to be deployed with your web solution. You use only the feature that you want.
Well, that's the point. You are deploying an entire set of features in form of a single DLL file and using just a small feature which can be easily replicated using simple JS trick which is easier to create, use, implement and thus in turn, hassle-free.
Not all controls in the kit use AJAX technique. There are some which use pure JS code. It's MS, who has clubbed everything in a single file and named it AJAX-something-something.dll!!!
-
Dec 11th, 2008, 01:08 PM
#10
Re: requirefieldvalidate control for all text boxes
 Originally Posted by rjv_rnjn
Just curious, why? AjaxControlToolkit.dll is a single library that is to be deployed with your web solution. You use only the feature that you want.
If you had to perform one single stored procedure call in your website project, would you write the code yourself or add a reference to the DAAB and use SqlHelper just to avoid writing 3 lines of code?
Both will work, one is overkill.
-
Dec 11th, 2008, 04:54 PM
#11
Fanatic Member
Re: requirefieldvalidate control for all text boxes
Ok..ok.. I get it! Don't beat me to death over it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|