C# - How To Validate If The Input Text For Both Of Them Are Not Both Null

Apr 12, 2010

I'm working on an ASP.NET/C# app.

I have 2 text boxes and I need to validate if the input text for both of them are not both null
ex:

if(string.IsNullOrEmpty(TextBox1.Text) && string.IsNullOrEmpty(TextBox2.Text) ) //FAIL!!! else

that is, at least one txtBox has values

I was planning on using a custom validator but it seems that the validation function only gets called when something is written on the textBox i'm using has the 'control to validate'. Now, that doesn't work for me since I want to show an error message when both text boxes are empty. Is there a way to make the validation function to be called with, for example a postback? Or is there any other better approach to this case than the custom validator?

View 2 Replies


Similar Messages:

Web Forms :: How To Validate Input Text Depending On Selected Value From Dropdown

Apr 12, 2010

I have 1 drop down, 1 text field and 1 command button i.e. "Search". Dropdown contrains following values

Type1
Type2
Type3

In textbox user will enter numeric or alphanumeric value

Here I want to check if 'Type1' is selected so user can enter only numeric value between 1000 and 2000, otherwise display some message "Entered value is not valid for "Type1". I want to display this message thru required validator error message property

If user select 'Type1' and 'Type2' then user can enter any alphanumeric value other than 1000-2000 numeric range.

I want to implement thru Search button or once user leave the textbox after entering value. Here I want to display message.

View 11 Replies

C# - Is There A Security Reason To Validate A Textbox Input If You Are Limiting The Max Length Of The Input

Oct 1, 2010

Since I'm new to coding and I'm trying to understand why here is a little more detail on the question.If you have a text box and you are limiting the input to say 2 charactrs do you really need to validate the input further? What I have is a text box that has a max length of 2. Is there a security reason to add a validator to the textbox. I should add this is in Asp.net.

View 8 Replies

Web Forms :: Can Validate A Hidden Input

Apr 4, 2010

I have an input...

<input
id="ratingField"
runat="server"
type="hidden"
/>

this hidden input is used by a star rating control. the user gives a star rating of 1 to 10 by clicking on the stars and some javascript detects which star was clicked and fills the input with the corresponding number.

I want to use a RequiredFieldValidator to ensure that the client has selected a star and if not return an error message to my validation summary.but the validator seems to be throwing an exception. How do I do this?

View 4 Replies

Web Forms :: Validate The Input Textbox

Nov 1, 2010

I have a textbox called "tax rate" which I need to validate the input... The only thing I need to ensure is that the value entered is a number (decimals ok of course). eg. the input might be "8.75" How do I write the validation expression?

View 4 Replies

Php - Validate If An Web Application Gets The Users Input Or Parameters?

Oct 21, 2010

I am always thinking about validation in any kind on the webpage (PHP or ASP, it doesn't matter), but never find a good and accurate answer. For example, a I have some GET-Parameter, which defines a SQL query like DESC oder ASC. (SQL-Injection?) Or I have a comment-function for user, where the data is also saved in a database.

Is it enought to check for HTML-tags inside the data? Should the validation done before adding it to the database or showing it on the page? I am searching for the ToDo's which should be always performed with any data given from "outside".

View 3 Replies

Web Forms :: Validate Input Has Up To 2 Decimal Places?

Sep 1, 2010

I need to validate hours put into a textbox. I want to allow hours to be from 0-24 and allow up to 2 decimal places. so it has to accept

0

0.00

1.5

2.25

but not 2.225 or 25

I put a range validator that check that the value is from 0-24 but it doesn't check that there are 2 decimal places or less. how do I do that?

View 3 Replies

Validation - Validate Integer And Float Input In Textbox?

Mar 4, 2010

I am using below code to validate interger and float in asp.net but if i not enter decimal than it give me error

<asp:TextBox ID="txtAjaxFloat" runat="server" />
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtAjaxFloat" FilterType="Custom, numbers" ValidChars="." runat="server" />

i have this regex also but its giving validation error if i enters only one value after decimal. [URL]

View 4 Replies

MVC :: How To Validate HTML Input Fields Using JQuery Inside Ajax.BeginForm?

Jan 24, 2010

How to validate HTML input fields using jQuery inside Ajax.BeginForm?

[Code]....

View 1 Replies

How To Validate User Input In TextBox Inside A FormView With MS SQL 2008 Database

Feb 5, 2010

VS2008 c#, asp.net 3.5, ms sql 2008How do I validate user input in TextBox inside a FormView [Insert Mode] with MS SQL 2008 Database?* FormView #fvInsertProjectInfo* TextBox #txtProjectNameCurrently, user could insert a new project using the FormView, but will only be found out that the project is already existed when pressing the INSERT button. To make it more user friendly, I would like to check that the database does not contain a record of the project the user trying to insert (by comparing value in txtProjectName with the Projects table in the database)

View 2 Replies

Validation - Using RangeValidator To Validate User Input On Client Side For Double Values?

Feb 4, 2010

I was using RangeValidator to validate user input on client side for double values.One of my user said that when he enters 5E-10, my range validator does not understand that number as a valid double.

View 1 Replies

Web Forms :: Value Cannot Be Null.Parameter Name Input Error

Mar 3, 2010

for some reason i get an error saying the following. i have tried to look it up on google but there seems to be nothing about this error.

View 2 Replies

WCF / ASMX :: Webservice Namespace - Input Is Null?

Nov 13, 2010

I have a ASP.NET webservice which is called by a Java client. The client sends a SOAP message as input but the problem is that it never reaches my webservice method. I always get null as input. I used TraceListener and saw this warning which may cause the problem:

The element was not expected in this context: <ListenerInput>..</ListenerInput>. Expected elements: http://client.ns.url/:ListenerInput.

This is what the client sends:

<?xml version="1.0" encoding="utf-8"?>
<S:Envelope xmlns:S = "http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>[code].....

View 2 Replies

MVC :: Radiobuttons Inserting 0 Instead Of Null If No User Input?

Mar 31, 2010

I have a group of radiobuttons. The field they are 'bound' to is of datatype tinyint (sql server), byte .NET. It is set to NOT accept nulls in the database column (col1) and no default value has been set for the column, or indeed, anywhere else.View code as follows:

<ul> <li><%= Html.RadioButton("col1", "1")%></li> <li><%= Html.RadioButton("col1", "2")%></li> <li><%= Html.RadioButton("col1", "3")%></li></ul><%= Html.ValidationMessage("col1", "*") %>
If the user doesn't select any of them, I would expect null to be that the model would attempt to insert into the database. I would therefore get a validation error that I can display to the user, prompting them to choose one of the options.owever, instead of null, the model inserts a 0 into the database. As this does not fail, no error is raised. Can anyone think why? Blowed if I can.I am not setting the default value to 0 anywhere, not in the mvc app or the database

View 6 Replies

AJAX :: ComboBox Runtime Error When Deleting The Text / '_optionListItems[...].text' Is Null Or Not An Object

Feb 2, 2011

I have a problem with the Ajax ComboBox from the Ajax Control ToolKit. When I want to erase the text in the ComboBox, I got this error:

"Microsoft JScript runtime error: '_optionListItems[...].text' is null or not an object". I only get this error when deleting the content of the Combox is the first action I do on the ComboBox. If I overwrite the text by entering something else before deleting this text, I got no error.

View 2 Replies

Web Forms :: Trying To Do Is Validate The Input Only When The Enter Button Is Clicked Not The Search Button?

Dec 7, 2010

I have a asp page with tow buttons search adn enter and asp required field validator in it, what I am trying to do is validate the input only when the enter button is clicked not the search button, right now when the search button is clicked it validates and throws an error.

View 2 Replies

Web Forms :: How To Validate The Text Box

Jan 20, 2011

I want to validate the text Box

1. It's not allowing only nubers

2.It's should be combination of numbers and alpahbets

3.It's should not allow only dateformat

View 2 Replies

How To Post And Validate "Named" Input In C#

Mar 30, 2011

I need to post a form to a 3rd party URL in C#. The input fields must be named to match what the third party is expecting (in this case "Email Address", etc). If I use a standard "input" tag I don't have a great way to validate the control. If I use an "asp:TextBox" like in this example, it will rename my field and screw up my post.

[Code]....

So the above renders the following. I need the name to be "Email Address", or I need a good way to validate the input field (this example is simplified, there are more fields and more regex validations).

[Code]....

View 2 Replies

Validate All Text Boxes In PlaceHolder

Nov 11, 2010

I've problem with validating all text boxes in PlaceHolder. I made PlaceHolder and I've no idea how to check that all textboxes have integer numbers as a text.

public void Made_Matrix (PlaceHolder Matrix, int Size){
for(int row=0; row < size; row++){
for(int col=0; col < size; col++){
TextBox TB = New TextBox();
Matrix.Controls.Add(TB);
TB.ID = TB + Convert.ToString(row) + Convert.ToString(col);
TB.AutoPostBack = "true";
}
Matrix.Controls.Add(new LiteralControl ("<br/>"));
}
}
public void TB_Validate (PlaceHolder Matrix, int Size){
for (int row = 0; row < size; row++){
for (int col = 0; col < size; col++){
string Ident = TB + Convert.ToString(row) + Convert.ToString(col);

how can i find text hidden in TextBox with ID from Ident? And how to check if it's numeric? I suppose that in .NET there's no function like IsNumeric(), am I right?

View 2 Replies

C# - Get Text Value Of Input From FindControl?

Dec 6, 2010

I know now normally you can get the value of a text input using the following:

txtName.Text

But because my input is inside of a LoginView I am using FindControl like this:

LoginView1.FindControl("txtComment")

This successfully find the text input but returns its type rather than the value. Adding the Text function at the end does not work.

View 3 Replies

How To Input Text Format As (hh:mm)

Mar 18, 2010

Give any sample links for input text will get as hh:mm format .for example if we open system date and time with in single text box we can edit hours and minutes .same like that i need examples in asp.net .

View 2 Replies

Web Forms :: How To Validate Text Box With Confirm Message

Apr 10, 2010

have Two textBox with RequiredFieldValidator and one Button with OnClientClick for Confirm message. How to validate the Text box before showing the confirm message popup

View 12 Replies

How To Validate A AJAX ComboBox With Empty Text

Dec 2, 2010

How should i validate if my AJAX ComboBox contains text? I have tried with the ASP.NET RequiredFieldValidator but it dosent work.

View 1 Replies

MVC :: How To Save Input Text In A List

Feb 15, 2011

I have a table including : StudentID,Mark

and I show them in a list and I want to input marks one by one:

<% foreach (var item in Model) { %>
<tr>
<td>
<%: item.StudentID %>
</td>
<td>
<input type="text" />
</td>
<%}%>

1-how can I save them in database which saves each mark for each StudentID in the list?

2- how can we send focus to next textBox by pressing Enter key in each textbox in the list?

View 1 Replies

Web Forms :: Validate Multiple Text Boxes In GridView?

May 27, 2010

I have an ASP.NET gridview where I allow the user to edit a record. I need to validate multiple fields as one. I need to require that the user either enter a first and last name OR a company name. All three cannot be blank. Most of the sample code I am finding does not address the text boxes only being visible while the gridview is in edit mode. When not in edit mode, the text boxes do not exist so
document.getElementById('<%= editFirstName.ClientID %>') throws an error upon page load.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved