Web Forms :: ControlToValidate Property Cannot Be Blank?
Jan 27, 2010I've been ditched by my developer who's run off without finished a project.
View 11 RepliesI've been ditched by my developer who's run off without finished a project.
View 11 RepliesI am having N numbers of Text boxes those are generating dynamically. I want to validate each textbox for Formate HH:MM:SS PM/AM so i dynamicaly create the validation control . but as the dynamic textbox has no ID , so what i have to pass to the Validation control for ControlToValidate Property ?
View 1 RepliesI've searched a fair bit round and tried a number of potential solutions, suggested on their respective threads on various sites, to which none have worked for me.
My objective is to make sure the date entered, and to be stored, is not 'less than' (before) the present datei.e. Booking a reservation for a restaurant.
The first is:
"The ControlToValidate property of 'cvDate' cannot be blank..."
I've tried specifying it in page_load and .aspx source, the same has happened in both, in addition to ValueToCompare. I cant understand why it cant detect it?
C# (ControltoValidate):
Csharp Code:
[code]....
<asp:TextBox ID="TextBox1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="ValidationFunction1"
ControlToValidate="TextBox1"
Display="Dynamic" />
And a validationFunction:
function ValidationFunction1(sender, args)
{
}
And i would like to know if, inside the function I could get the Control to validate something like: var v = sender.ControlToValidate;
How do get the value in the JavaScript function identified in ClientValidationFunction property that was entered in the control that was identified in the ControlToValidate property of a asp:CustomValidator control?
function MyValidateFunction(sender, args) {
//want to get value of MyControl
}
<asp:CustomValidator
ID="cvAlarmedLocationAddress"
runat="server"
ControlToValidate="MyControl"
ClientValidationFunction="MyValidateFunction"
Text=""
/>
I have site with two text boxes and dynamically create validation control. This is code from .aspx file:
<form runat="server">
<asp:TextBox AutoPostBack="true" ID="TextBox1" Text="" runat="server" Width="200px"
OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Visible="True" Width="200px"AutoPostBack="true"></asp:TextBox>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
<asp:TextBox ID="ValidationTB" runat="server" Visible="true"></asp:TextBox>
</form>
This is my code-behind:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (TextBox2.Visible)
{
if (!String.IsNullOrEmpty(TextBox1.Text) && String.IsNullOrEmpty(TextBox2.Text))
{
RequiredFieldValidator RequiredFieldValidator1 = new RequiredFieldValidator();
RequiredFieldValidator1.Enabled = true;
RequiredFieldValidator1.ErrorMessage = "Second field required";
RequiredFieldValidator1.Display = ValidatorDisplay.Dynamic;
RequiredFieldValidator1.ControlToValidate = "TextBox2";
Panel1.Controls.Add(RequiredFieldValidator1);
RequiredFieldValidator1.Validate();
}
if (!String.IsNullOrEmpty(TextBox2.Text) && String.IsNullOrEmpty(TextBox1.Text))
{
RequiredFieldValidator RequiredFieldValidator1 = new RequiredFieldValidator();
RequiredFieldValidator1.Enabled = true;
RequiredFieldValidator1.ErrorMessage = "First field required";
RequiredFieldValidator1.Display = ValidatorDisplay.Dynamic;
RequiredFieldValidator1.ControlToValidate = "TextBox1";
Panel1.Controls.Add(RequiredFieldValidator1);
RequiredFieldValidator1.Validate();
}
if (!String.IsNullOrEmpty(TextBox2.Text) && !String.IsNullOrEmpty(TextBox1.Text))
{
if (Convert.ToDateTime(TextBox2.Text) < Convert.ToDateTime(TextBox1.Text))
{
ValidationTB.Text = null;
RequiredFieldValidator RequiredFieldValidator1 = new RequiredFieldValidator();
RequiredFieldValidator1.Enabled = true;
RequiredFieldValidator1.ErrorMessage = "Bad range of dates";
RequiredFieldValidator1.Display = ValidatorDisplay.Dynamic;
RequiredFieldValidator1.ControlToValidate = "ValidationTB";
Panel1.Controls.Add(RequiredFieldValidator1);
RequiredFieldValidator1.Validate();
}
}
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
RegularExpressionValidator RegularExpressionValidator1 = new RegularExpressionValidator();
RegularExpressionValidator1.ValidationExpression = @"^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$";
RegularExpressionValidator1.Enabled = true;
RegularExpressionValidator1.ErrorMessage = "Bad format of date";
RegularExpressionValidator1.Display = ValidatorDisplay.Dynamic;
if (!String.IsNullOrEmpty(TextBox1.Text))
{
RegularExpressionValidator1.ControlToValidate = "TextBox1";
Panel1.Controls.Add(RegularExpressionValidator1);
RegularExpressionValidator1.Validate();
}
if (!String.IsNullOrEmpty(TextBox2.Text))
{
RegularExpressionValidator1.ControlToValidate = "TextBox2";
Panel1.Controls.Add(RegularExpressionValidator1);
RegularExpressionValidator1.Validate();
}
}
}
TextBox ValidationTB is just to make validate on empty control. This validation doesn't work, when I try:
1. To first textbox enter for example: 2009-09-09
2. To second textbox enter for example: 2009-10-09 Now, everything is OK.
3. I change my first textbox on for example 2009-12-09 I get error Bad range of dates - it's OK.
4. I correct first textbox on 2009-09-09, message disappear-OK.
5. Again enter to first textbox 2009-12-09 - I don't have error, but it should be.
What strange - in debug mode I can see, that in code:
if (Convert.ToDateTime(TextBox2.Text) < Convert.ToDateTime(TextBox1.Text))
{
ValidationTB.Text = null;
RequiredFieldValidator RequiredFieldValidator1 = new RequiredFieldValidator();
RequiredFieldValidator1.Enabled = true;
RequiredFieldValidator1.ErrorMessage = "Bad range of dates";
RequiredFieldValidator1.Display = ValidatorDisplay.Dynamic;
RequiredFieldValidator1.ControlToValidate = "ValidationTB";
Panel1.Controls.Add(RequiredFieldValidator1);
//In debug window: RequiredFieldValidator1.ControlToValidate = "TextBox2"
RequiredFieldValidator1.Validate();
}
instead of ValidationTB control, RequiredFieldValidator1.ControlToValidate is set to TextBox2 (it isn't empty, so I haven't error message). Why TextBox2 is set to RequiredFieldValidator1.ControlToValidate instead of ValidationTB textbox and how I could solve this?
I'm using the following code to iterate through a list of validators on the page. For each validator, I want to set the background color for the control its responsible for validating. The problem I'm having is that FindControl method is always returning null. From searching the web, it appears the problem is that the page has a master page. Whether this is the issue or not, it's obvious that the FindControl method cannot find the ControlToValidate control.
Method used to iterate all validators on a page:
protected void ShowControlsToValidate(Page page)
{
if (page == null)
return;
[Code].....
Markup showing control and it validator:
[Code]....
I have a form which a user can fill in x times with the data they want too. The form is posted to the following Action.
[HttpPost]
public ActionResult Manage(ProductOptionModel DataToAdd)
{
if (!ModelState.IsValid)
{
return View(DataToAdd);
}
var ProdServ = new ProductService();
if (DataToAdd.ID != 0)
{
//Edit Mode.
DataToAdd = ProdServ.EditProductOption(DataToAdd);
ViewData["Message"] = "Option Changes Made";
}else
{
//Add
DataToAdd = ProdServ.AddProductOption(DataToAdd);
ViewData["Message"] = "New Option Added";
}
var RetModel = new ProductOptionModel() {ProductID = DataToAdd.ProductID};
return View(RetModel);
}
So at the bottom I blank the model (Leaving just the required field) and then return to the view. However the view holds the data from the previously submitted form. I have debugged the code and checked that the RetModel variable is empty.
Can anyone add a complete input about how to create Parent Property with multiple child properties or in short nested properties.
Example: Style tag: which has properties like font, color, display... etc? which accept objects and its value.
[code]....
As soon as Rainbow property is typed, user should get intellisense for list of number of colors. Then accordingly user can select list of those colors and assign a value to them.
I need to set a style property of an element to the value returned from a code-behind property. I have done this in the past, but it now seems everything I try fails. I get an error telling me that the literal is not formed correctly.These are some of the arrangements I have tried:
[Code]....
I've finally figured out an issue I'm have with a zip code field being entered in a text box of a details view in edit mode. I'm trying to understand why i have the issue though. I don't understand why it keeps occurring.his what happens with the zip code field. I've been able to make it reoccur numerous times. If the details view is put in edit mode and the record is updated with the original 5 digit zip code, unaltered in any way, my regular expression validator catches it and doesn't let the update happen. If I change the replace the 5 digit zip code with a new one the update goes through fine. This new value can be a different or the same 5 digits and the update will work. If I don't change the value at all though the update will not go through.
View 8 Repliesmy web application i use FindControl to retrieve a Control By Name (it returns an System.Web.UI object). The control can be of various type and I don't want to treat them differently: I'd like to set the Text property to a defined string. I hope there's a class that I may use to cast the control and set the Text property.
View 8 RepliesI have created master page in my application using site map and have some web forms. When I click a link from site map I would like to open in blank page like popup window. How can I do that ?
View 3 RepliesI have a field that is a DropDownList. When in the insert mode I want that field to be blank - It currently is displaying the first record in the table it pulls from. I was expecting to see an initial value setting in the DropDownList properties but do not. For example - suppose I have a field named locations that consist of 4 location (below). In "Insert" mode, location currently displays Dallas. I want it to be set to blank initially and the user select one. What am I mssing?
View 4 RepliesI have a simple issue..the user types his/her name in a textbox. Accidentally if a space is entered after a name or before, is it possible for me to trim it while accepting and not raise any error (which actually arises when the textbox is empty)?
View 5 RepliesI am using RTE with Textview and htmlview. When i try sending email on a button click with my Textview option enabled "By Default" i receive a blank email.Hwne i switch it to htmlview, i am reciving the email having Text i wrote with all the html coding.
How can i get my Textview mode working.
I have to play audio on itemcommand of listview in my site for which I have written the following code:
<object id="Audio" width="0" height="0" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="URL" value="<%=Path %>" />
[code]...
So what I'm trying to accomplish is this
[Code]....
The user control has public properties named accordingly and the page has protected properties accordingly which I've verified have the desired values.
For some reason the values are always empty strings or 0s in the usercontrol, no matter what the page property is.
Is there any difference between accessing a property that has a backing field
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
versus an auto-property?
public int Id { get; set; }
The reason I'm asking is that when letting ReSharper convert a property into an auto property it seems to scan my entire solution, or at least all aspx-files.
I can't see any reason why there should be any difference between the two from outside the class. Is there?
In the Web.Config we have a timeout property. Ex:
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" timeout="2880"/>
</authentication>
When loggin in, we can specify a ticket expiry date. Ex:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, id.ToString(), DateTime.Now, expiryDate, true,
securityToken, FormsAuthentication.FormsCookiePath);
Why there's two places where I can set expiration info about forms-authentication? What's the difference between them? What has more relevance?
I have three dropdowns, the second one is visible only if first dropdown selection is "Sunshine"
I have a blank space between when the second dropdown visible = false
it is possible to avoid this blank space, between the dropdowns.
I have a sample app below
[Code]....
I want add blank space infornt of hyperlink control in panel
[Code]....
[Code]....
I am trying to figure out how to get fresh photo album. I am able to upload pictures to the database and display them(using handler & listview), but when I go to create a new album it shows the previously uploaded pictures of the first one. In the database it shows a new ImageAlbumID so it is creating a new album, but just shows the old pictures of previously created albums. I want just a blank page with the AjaxUploader. the code:
<%@
Page Title=""
Language="VB"
MasterPageFile="~/masterpages/postmaster.master"
[code]...
I have created login page in which if user credential are incorrect it will show the message through jquery notification bar.But, what is happening when page is being postback it will show complete blank page after that it will load the controls of that page and then the error message will be shown if it is there. So, its taking quite a long time .So, how can we access or load the page in faster way?? or should i make any changes while postback?
View 2 RepliesNow for the final thing! I am trying to open up the page in a new window but get a string error that I can't figure out:http://churchmouse.firkinpubs.com%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20target=_blank/Here is my code
myMarker.Text =
"<b>" & (irow("BarName")) &
"</b>" &
"<br/>" & (irow("Address")) &
"<br/>" & (irow("BarDescription")) &
"<br/>" & (irow("Email")) &
"<br/>" &
"<a href='" &
"http://" & (irow("BarUrl")).ToString &
"target=_blank" &
"'>" & (irow("BarUrl")) &
"</a>"