Required field/fields

hello , I am having four upload file controls , next to them 4 textbox's , and 1 checkbox , if the checkbox is checked , only 1 of the textbox's become available ...I want to check if each upload file if it has a file and the textbox's next to it isnt empty , or the only available one isnt empty , the idea that i am uploading 4 files or less , each uploaded file must have a title for it in the textbox , or one title for all the files , If someone can help me in the idea of the code for that in the upload button....I tried putting XOR code between each upload and textbox but internet explorer says webpage cannot be displayed when i press the upload button , i thought of required field validator that has it's valuetocompare changed during runtime , but I already had previous problems with it and i asked for it in asp.net forums and didnt get an answer...please help me in any thought for this , thanks alot !

0
Mazenx
11/17/2008 2:32:56 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

8 Replies
848 Views

Similar Articles

[PageSpeed] 10
Get it on Google Play
Get it on Apple App Store

Hi,

It should be possible to use a customValidator control on this on.  Just set it up on the page next to you file upload section, and give it an apporpriate error message.

<asp:customvalidator id="cvFileUpload" runat="server" errormessage="Error with file upload titles." clientvalidationfunction="fileUploadValidation">*</asp:customvalidator>

I have put together an example for the javascript validation function.

function fileUploadValidation(source, arguments)
{
 if (this.document.getElementById('CheckBox').checked == true)
 {
  // all files should have own title
  for (i = 1; i <= 4; i++)
  {
   if ((this.document.getElementById('uplFile' + i).value.length != 0) && (this.document.getElementById('txtTitle1' + i).value.length == 0))
    arguments.IsValid = false;
  }
 }
 else
 {
  // only one title all files
  if (this.document.getElementById('txtTitle1').value.length == 0)
   arguments.IsValid = false;
 }
}

In the above code you will need the full controlID, you can get this from right click on page and choose view source.  Also here I have assumed that you have called them uplFile1 to uplFile4 and same on text boxes.  If you have named them differently you may just want to change the loop above to a few if statements instaed.

 

Hope this helps.

 

Dean

0
DeanHunter
11/17/2008 4:08:46 PM

hmmmm...I wanted it to be by c# but i might use this javascript if it's the only solution at the moment , but in your code , if any one from the four file uploads is empty it's gonna give error , but I dont want that ...cause I might just upload 3 ones .

 

0
Mazenx
11/17/2008 5:00:39 PM

DeanHunter:

   if ((this.document.getElementById('uplFile' + i).value.length != 0) && (this.document.getElementById('txtTitle1' + i).value.length == 0))

 

yes, sorry I didn't test the code.

My thinking here was if uplFile was not 0 (had a value) and txtTitle has no value return false.  Maybe it could be altered to something like this

if (this.document.getElementById('uplFile' + i).value.length > 0)

{

 if (this.document.getElementById('txtTitle1' + i).value.length == 0)

  arguments.IsValid = false;

}

Custom validators  can be used to validate a individual control too.  Maybe a individual one like above snippet on the four txtTitle boxes.  You could just add in a check to see if the check box is checked.

Would you not be better to check this client side to save posting back a page when it is not valid?

0
DeanHunter
11/17/2008 5:43:37 PM

hmmm , am sorry for the late reply but couldnt reply earlier

I tried the code you gave me , but there was always an error on lines containing this.document.getelementbyid , it says object required

i guess the problem goes cause of one of of these two reasons

the first one , that most of my page controls are inside a template in a loginview so the code cant reach them

second , i am doing an autopostback when i check the checkbox i have

where do u think the error lies ?!

thanks alot

0
Mazenx
11/17/2008 7:57:45 PM

There is a autoPostBack property on the checkbox control, you probably just need to set it to false.

The control will have a different name in your html source that is sent to the client causing you the problem of finding it, if you right click on the page and choose view source you will get it in notepad.  Then do a quick search on what the control is called and get the full name, e.g. a control on a user control callen Uc_Main would likely be Uc_Main_txtMyTextBox(it is the Id of the control you want so will ptob not be the one with the $ sign).  Or maybe something like ctl00_cph_Main_txtMyTextBox.

The javascript is case sensitive so you should keep the case on 'this.document.getElementById', or '$get' should work instead.

0
DeanHunter
11/18/2008 9:27:09 AM

Hi,

I just quickly put this together to demonstrate.  I dont have the controls on a user control but you shouldn't have a problem getting your control Id.


<script language="javascript">
    function dissableTextBoxes() {
        if (this.document.getElementById('Checkbox1').checked == true) {
            this.document.getElementById('Text2').disabled = true;
            this.document.getElementById('Text3').disabled = true;
        }
        else {
            this.document.getElementById('Text2').disabled = false;
            this.document.getElementById('Text3').disabled = false;
        }
    }
    function fileUploadValidation(source, arguments) {debugger;
        if (this.document.getElementById('Checkbox1').checked == false) {
            // all files should have own title
            for (i = 1; i <= 3; i++) {
                if ((this.document.getElementById('FileUpload' + i).value.length != 0) && (this.document.getElementById('Text' + i).value.length == 0))
                    arguments.IsValid = false;
            }
        }
        else {
            // only one title all files
            if (this.document.getElementById('Text1').value.length == 0)
                arguments.IsValid = false;
        }
    }
</script>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
        Name all the same
        <input id="Checkbox1" type="checkbox" onclick="dissableTextBoxes()" /><br />
        <asp:FileUpload ID="FileUpload1" runat="server" />
        Title:<input id="Text1" type="text" /><asp:CustomValidator
            ID="CustomValidator1" runat="server" ErrorMessage="File must have a title." ClientValidationFunction="fileUploadValidation" Text="*"></asp:CustomValidator>
        <br />
        <asp:FileUpload ID="FileUpload2" runat="server" />
        Title:<input id="Text2" type="text" /><br />
        <asp:FileUpload ID="FileUpload3" runat="server" />
        Title:<input id="Text3" type="text" /><br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" />
        <br />
    </div>
    </form>
</body>
</html>

I have tested this, so it should work for you.

0
DeanHunter
11/18/2008 9:57:48 AM

Hello dean , thanks alot it worked for me , my problem was just with finding the controls , and I did as you told me , I ran the application and viewed the source and got the titles from there and it worked...thanks alot !

0
Mazenx
11/18/2008 6:34:21 PM

Your'e welcome.

Nice to know it's you got it sorted :)

0
DeanHunter
11/19/2008 9:22:33 AM
Reply:

Similar Artilces:

When is a Required Field not a Required Field!
Hi there I have a data collection ASP. NET form (with C# code behin) that is used to collect scientific data. Some fields are required but others will only be required based on the user's selection. I don't really know the best way of dealing with this in ASP so would appreciate any advice?  A simple wordly example of this would be an onlne car insurance application form. If the person was asked if they had any previous accidents, then the 'previous accidents' section would thus be required. However, if the person said "no" to previous accidents, then th...

How return not required fields to required fields
--_004_190C663294B0BF479CBA0C904230EE98AC1F1777B0Argonmailteln_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, I want to return Fields =AB assign to =BB and =AB Status =BB to a required = fields. Can any one help me ? Cordialement, Marwa ARBI Ing=E9nieur d=E9veloppement Groupe TELNET Parc Technologique - 2083 Cit=E9 la Gazelle T=E9l. : [+216] 71 858 055 Fax : [+216] 71 858 056 www.groupe-telnet.net<http://www.groupe-telnet.net> [cid:image001.jpg@01CDBE84.A8FA5130] --_004_190C663294B0BF479CBA0C9042...

one Combbox field. How to get the other field ?
Hi I work with a accessdatasource and i have one field in my combobox. When i select one value from my combobox how can i get other field of the database in one textbox? Thank youMario Lopes HiWe may use the the Combbox's SelectedIndexChanged event to fetch the other field value either by fetching data from the database or else from a dataTable or dataView which the data is already filled.  Hope this will help.   And be sure to set AutoPostback = TRUE in your ComboBoxRegards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your ...

Getting a field validator to hide other fields
Hello there. I have a page with a few fields, a few validators and a few buttons.When one button is clicked it causes some of my field validators to run. Is there a way to get a field validator to clear a label or textbox when it displays its own error message? You should use custom validator, in the ServerValidate event you can do all that you want like clearing the field value.Trirange Portal Server Online Demohttp://www.trirange.com/demo/ Hello, you should use a CustomValidor script and create a client-side javascript function to validate the data entered, and clear the field if the ...

Displaying fields in same was as <%=(field)%> in .net
Hi, I am very new to .NET after aloways programming in ASP. Thought I would try and rewrite a site of mine using the new beta and Visual Web Developer. First impressions are good, there are some great tools there to save a load of time with the Datagrids etc. However I am stuck on how to do something I use 99% of my time in ASP and is holding me up! Before I would create a recordset using sSQL = "SELECT Name FROM Albums WHERE Uid = 1 ORDER BY Name" Set RsAlbum = Conn.Execute(sSQL) Name = RsAlbum("Name") Then in the HTML I could display the result by using <%=(Name)%> ...

problem with required field validator for mandatory fields
Hi there, In my webpage i m hving txtbox financial year , txtbox from year, txtbox endyear. Intially all three r mandatory fields. I want to do like this. when user enter value in financial year txtbox and submit then fromyear and endyear fields should not be mandatory. currently when submit it will check for all three. Is there any idea to implement it using codebehind or javascript. Thanks  hi try using textbox (financial year)  onblur event in javascript and here you can disable/enable required fields (Please first check value of text (financial year) in javascript.).u...

Required Field for do-start-workflow
I've searched, but can't seem to find a definitive answer... When starting a workflow from a driver do you have to include ALL the fields on the form or just the ones labeled as required? The list of attributes between my Pre-Activity and Post-Activity is a bit different, which one should I be focusing on? I have a lot of fields on the form, but only 3 or 4 are passed out through post activity so I'd prefer to just send those if possible. ~F -- fevans ------------------------------------------------------------------------ Have a look into the PRD file...

Tab from field to field
I am writing a data entry application for a mobile device we will probably be using pocket pc 2002 but may decide to go with pocket pc 2003, is it possible to tab between fields? The user does not want to have to use the stylus to go from field to field. Any sample code would be helpful ThanksMaria...

getting row index of an template field (linkbutton field)
Hi, i have a gridview where one of the column is as below <asp:TemplateField><ItemTemplate> <asp:Label ID="lbl" runat=server Text = '<%# Bind("delete_on") %>' ></asp:Label></ItemTemplate> <EditItemTemplate> <asp:LinkButton ID="lb" runat=server Text = "Inactivate" CommandName="change_status" COMMANDARGUMENT=????? ></asp:LinkButton> </EditItemTemplate></asp:TemplateField>  I can get the index for a boundfield through e.CommandArgument (in GridView_OnRowCo...

Way to get Original value of the field into computed field
Hello, My Environment is PB10. Is there any way to get the orinal value (Similar to the Original buffer value in olden days) of the field into computed field. Thanks, Sra "Sravan" <sr.100102@gmail.com> wrote in message news:121a4797-cc11-4927-8613-ba3f69a6e009@e31g2000vbm.googlegroups.com... > Hello, > My Environment is PB10. Is there any way to get the orinal value > (Similar to the Original buffer value in olden days) of the field into > computed field. Just add ".original" to the column name. E.g., transaction_date.original ...

Required field Validators giving error when other fields need to be changed.
I've a user control in my asp page. There are 2 sets of fields. First set is to change the password.  The fields in the set are text boxes for password, confirm password  and a button to save password. The second set is to change preferences. In this set there is a text box to change email, a check box and save button. I want both the set of fields and buttons to work independently. i.e the user can change password and change preferences or just change one set of fields. Earlier there were no required field validators for the password fields. Eve...

display a message in gridview field if no data gets returned in that field
Hello! I have a gridview that output messages like email..On the 'FROM' column i'd like to display a message if there is no name to display as some users might delete their account. The subject and date are available because they pull from another table. I am doing a join on the table that has the user info. Is there a way to check if the field is empy in gridview then display a message. Or is there a better way of doing this. Thanks. James  one wuick way i would suggest is to put a isnull function in the SP that returns the valuesThanksSkuPlease remember to click “Mark a...

Can a field in Gridview be a Hyperlink field as well as Template field?
I have to add Template field  to Gridview and use data binding statement such as "<%# GetData(Eval("DType").ToString())%>" in the ItemTemplate. so that column retrieve/shows GetData("DType") values. When user clicks on this column it should redirect the user to another page, showing selected/clikced datarow . I think it is to do with Dynamic Hyperlink Field. I like to know can a column be a Hyperlink field as well as Template field so that i can use data binidng statement as above and do hyperlink task as well. your quick suggestion ...

.NET Required Field Validator not working
I am using .NET Framework 2.0 Required Field Validator to validate my form.  The validation worked great in localhost:xxxx, but when we deploy to the web server the RFV stop working.  In other words, the user clicks on the button and nothing happen.  The validator didn't fire. is my code the culprit or the web server setting? <div id="validatorErrorContainer" align="center"> <asp:Panel ID="Panel2" runat="server" HorizontalAlign="Left" Width="85%"> <asp:ValidationSummary ID="GridValidationSu...

Web resources about - Required field/fields - asp.net.getting-started

Some Assembly Required (radio program) - Wikipedia, the free encyclopedia
Some Assembly Required is a sound collage radio program in the United States, produced in Minneapolis , Minnesota . It is the first radio show ...

Third-Party Apps No Longer Required To Create Facebook Promotions
Facebook Tuesday announced updated guidelines for promotions on the social network, and the most prominent change was the removal of the requirement ...

Security Check Required - Facebook
Facebook logo Email or Phone Password Keep me logged in Forgotten your password? Sign Up Security Check Please enter the text below Can't read ...

Action required for new Graph API Webhooks
Action required for new Graph API Webhooks

Facebook opens up promotions policy; third-party apps no longer required
Another step in its simplification process , Facebook is making it easier for pages to run promotions or contests , by removing the requirement ...

UP - Tracker Required (UP/UP24/UP MOVE) on the App Store on iTunes
Get UP - Tracker Required (UP/UP24/UP MOVE) on the App Store. See screenshots and ratings, and read customer reviews.

The #Portland #airport #carpet required selfie. #PDX #pdxairport - Flickr - Photo Sharing!
Explore domesticat's photos on Flickr. domesticat has uploaded 6624 photos to Flickr.

How Create Blank App Icons On Your Home Screen - No Jailbreak Required! - YouTube
Link to tutorial: http://bitly.com/iemptylink Follow me on Twitter: http://www.twitter.com/macmixing Like my Facebook page: http://www.faceb ...

Urgent action is required to help Arab Christians
Muslims have a key role to play in preserving a continued Christian presence in the Middle East, writes Michael Young

Position vacant: Queenslander required to beat up Paul Gallen
It should be the easiest job vacancy to fill in the entire state.

Resources last updated: 12/14/2015 2:16:45 AM