validate Textbox in Web User Control from web form?

ASP.NET 2.0

I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc).

I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control.

So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there?

Thanks!

 

0
justinsaraceno
5/23/2006 7:42:48 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
2284 Views

Similar Articles

[PageSpeed] 56

The error message should occur wherever you place the validation control.

HTH,
Ryan


Ryan Olshan
ASPInsider | Microsoft MVP, ASP.NET
http://ryanolshan.com

How to ask a question
0
StrongTypes
5/23/2006 8:10:46 PM

Ryan,

Yes - thank you.  I know that's how it would work if I was validating a regular server control on my web form.

However, I want to have a validator on my web form that validates a textbox in a web user control.  If I create a validator on my web form and look at its properties in the property window of VS2005, I don't see my web user control as an option to be the field validated.

Make sense?

0
justinsaraceno
5/23/2006 8:18:58 PM

Oh. Nevermind. This was one of those things that I read 2x and thought I got it, then submitted and understood the actual thread. Smile [:)]

At the moment, I'm not seing this as easy to do, so let me give this some thought.

Ryan


Ryan Olshan
ASPInsider | Microsoft MVP, ASP.NET
http://ryanolshan.com

How to ask a question
0
StrongTypes
5/23/2006 8:21:12 PM

I am still relatively new to ASP.NET and pretty much any kind of MS specific development.

I realize it is two month later so I'm sure you've either figured out your problem or moved on.  I was hoping to do something similar, yet take it slightly further.  I want to do the same thing, but have validators enableclientscript="true" property set.  I have been able to accomplish what you want with server side validation by adding the ValidationPropertyAttribute: attribute to the user control class definition as follows.

[ValidationPropertyAttribute("SelectedDate")]
public partial class DatePicker : System.Web.UI.UserControl
{
/// <summary>Gets or sets the DatePicker Date text.</summary>
  public string SelectedDate 
  { 
    get 
    { 
      return txtDate.Text; 
    } 
    set 
    { 
      txtDate.Text = value; 
    } 
  }
....
}
[ValidationPropertyAttribute("SelectedDate")] [ControlValuePropertyAttribute("SelectedDate")] public partial class WebUserControl : System.Web.UI.UserControl { #region fields //determines if txtDate is autopopulated with current date on pageload bool _autoPopulateCurrentDate = false; #endregion fields #region Properties /// Gets or sets the DatePicker Date text. public string SelectedDate { get { return txtDate.Text; } set { txtDate.Text = value; } }
0
D_Stevens
7/24/2006 7:43:27 PM

sorry about that, apparently if you hit the tab key when entering text the focus changes to the "post" button, then if you hit space real quick it submits.

Anyways, what I've found is that the client script generated automatically by the validators does not work with my user control.  I'm assuming that this is because a postback is required to return txtDate.Text; from the user control property "SelectedDate".  Is there another way to make this property available to the client script generated by the validators.  Basically I'm trying to avoid writing a new validator with javascript and using the clientID property of the text box inside the user control and breaking the nice data abstraction model, which is the whole reason I made a user control in the first place.

Hopefully that made some sense to somebody out there

0
D_Stevens
7/24/2006 7:51:00 PM

The ValidationPropertyAttribute is built around server side concepts. After all, it identifies a property on a server side object.

The only way to get the existing client-side validators to work is by abandoning your UserControl idea. The client-side validators need the ControlToValidate's ID to point to the actual TextBox control, because they try to retrieve the value of <input type='text' id='[ClientID of the textbox]' />.

Suggestion: instead of creating your own Usercontrol for a datepicker, use one of the many that have been created (and are not usercontrols, so they setup their ID to work property with client-side validators). Many of them provide a good popup calendar that uses javascript to handle user's clicks so there is no post back. You will find Datepickers at this site's control gallery, www.123aspx.com, and www.411asp.net. Mine is Peter's Date Package.


--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
7/24/2006 10:47:58 PM
Thanks for the reply, very informative
0
D_Stevens
7/25/2006 6:58:07 PM
Reply:

Similar Artilces:

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspxSSNPlease remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it p...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

web web web
Name: bahadir Email: sensiz_olmuyor_t1_at_hotmail.com Product: Firefox 2 Beta 2 Summary: web web web Comments: web sayfası yapmak Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Interaction between Web User Control & Web form
Ok, I want to create my first Web User Control which is used for file uploading. It's very simple, consist only of the <asp:FileUpload> and <asp:Button> control. The button has one server side event which is resizing the uploaded image to two different images (stored as byte[] in the cs file). So, my question is how I can send these two arrays of type byte to the Web form where the web user control is inside. I thought it should be possible to write something like this in the Web form:<uc1:FileUploader ID="uploader" runat="server" OnUploaded="recieveImages" />So that means ...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Event handling web user control buttom in web form
How would I handle the button1 click event from a web user control on a web form in the codebehind? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MsgBox("test") End Sub does not work. Button1 is in the web user control. How would one handle the event in the page the web user control is embedded in? nevermind. it all came down to the class declaration in the codebehind file for the user control. It was originally webusercontrol2 and I renamed the ascx file to datesel.ascx and it never changed t...

Web resources about - validate Textbox in Web User Control from web form? - asp.net.web-forms

Credit Card Validate on the App Store on iTunes
Get Credit Card Validate on the App Store. See screenshots and ratings, and read customer reviews.

Who Is Going to Shoot Obama? Paul Broun Chuckles, Validates Question - YouTube
Republican Congressman from George Paul Broun chuckles and does not even come close to denouncing a question asked by a constituent at a town ...

PM says MH370 debris find 'validates search'
Experts say recovered MH370 debris is consistent the area being searched in the southern Indian Ocean.

Bill to validate ICAC findings rushed through state parliament
A bill to validate past findings of the state's corruption watchdog has been rushed into NSW Parliament in an attempt to head off legal moves ...

Fracking report validates environmental concerns in N.W.T.
... Kenyon of the Pembina Institute. A director of the Pembina Institute in Edmonton says a new report on the risks of shale gas development validates ...

【medical-news】Study First to Validate That Singing Can Help People Learn a Foreign Language - 医药生命科学动态跟踪 ...
只是新闻而已Fernanda Ferreira’s family emigrated from Portugal to Canada when she was very young. There, like most Canadian children, she learned French ...

Bulgaria, China validate postage stamp on 65th anniversary of ties
the,stamp,postage,bilateral,relations Bulgarian and Chinese officials in Sofia on Friday validated a postage stamp dedicated to the 65th anniversary ...

IXIA : Selected by China Network World to Validate High-Performance Cisco ...
IXIA : Selected by China Network World to Validate High-Performance Cisco ... 4-traders (press release) BEIJING - June 25, 2013 - Ixia (Nasdaq: ...

Apple Watch uses constant skin contact to validate Apple Pay purchases
... will the device make sure payments via Apple Pay are secure? Both the iPhone 6 and iPhone 6 Plus have the convenient Touch ID sensor to validate ...

Like You Really Need To Validate Your Social Media Presence….
How many Fortune 500 companies are blogging and using social media, and what can law firms learn from them?

Resources last updated: 12/1/2015 9:27:17 PM