How do I validate textboxes in a datasource, windows form, c#

You could use your validation code at the textbox TextChanged event so before someone presses the button the validation will happen.. In case user doesn't change the textbox and remains empty or the default value you have you can write an if statement before the try block on the button click event "raising" error and showing the relevant message to the user..Especially for the "Student Type" in case that the types are explicitly defined and the user has to choose among some values you could use combobox instead of textbox. At the combobox drop down event you could fill the combo list of values as shown on the example below.
Of course again you could validate for no value selected with an easy if statement before the try block on the button click event..
cbosttype.Items.Clear(); cbosttype.Items.Add("Type 1"); ...

What is the easiest way to validate textboxes that need to be checked before they go through. I have 2 tables I have to insert my data into as well and that's just for one group, in total I have 3 groups but just a helpful tip towards the one will be fine.It needs to be checked before it runs so how would I do it before the try/catch block and still just use the one button click.I have the main table which is 'Person' and then 3 sub tables; 'Student', 'Teacher', 'Administration'.Not all the textboxes need to be validated. sAdd2.Text and StudentType.Text.My normal code isprivate void sNew_Click(object sender, EventArgs e) { try { personTableAdapter.Insert(sFirstName.Text, sSurname.Text, Convert.ToDateTime(sDoB.Text), sPhone.Text, sAdd1.Text, sAdd2.Text, sSuburb.Text, sState.Text, sPostcode.Text, StudentType.Text); ...
This topic first appeared in the Spiceworks Community

Similar Messages

  • How can I validate a date field in Portal Forms

    I have a date field in portal forms that I want to perform validation on to make sure it's in the proper format before being accepted (mm/dd/yyyy). How can I validate against that field?

    Hi Ben,
    I took the time to test and revise. This is code that will validate a date entry (format MM/DD/YYYY). Just paste this in the "Before the start of the form..." window of the Additional PL/SQL code section of the form. Then add validateDate(); into the onBlur event window of the field in question. Replace the CYCLE_END_DATE with the field name in question.
    HTP.P('
    <SCRIPT LANGUAGE=javascript>
    function validateDate() {
    var ddObj;
    var mmObj;
    var yyObj;
    var day;
    var mon;
    var year;
    var field_val;
    var field_name;
    for (var j=0; j < document.forms[0].elements.length; j++) {
    field_name = document.forms[0].elements[j].name;
    field_val = document.forms[0].elements[j].value;
    if (field_name.substring(field_name.indexOf(''DEFAULT.'') + 8, field_name.lastIndexOf(''.01'')) == ''CYCLE_END_DATE'') {
    var delimPos = field_val.search(/\//i);
    if (delimPos < 0)
    alert(''Invalid date entry! Please enter in MM/DD/YYYY format. '' +
    ''e.g, Dec 21, 2003 would be entered as 12/21/2003'');
    else
    if (field_val.length != 10)
    alert(''Invalid date entry! Please Please enter in MM/DD/YYYY format. '' +
    ''e.g, Jan 1, 2003 would be entered as 01/01/2003'');
    else {
    month = field_val.substring(0, field_val.indexOf(''/''));
    day = field_val.substring(field_val.indexOf(''/'') + 1, field_val.lastIndexOf(''/''));
    year = field_val.substring(field_val.lastIndexOf(''/'') + 1, 10);
    /* Need to subtract 1 from value because in Javascript, January begins with 0
    and ends with 11 for December */
    month = month - 1;
    ddObj = new Date(year, month, day);
    mmObj = new Date(year, month, day);
    yyObj = new Date(year, month, day);
    if (ddObj.getDate(ddObj.setDate(day)) != day)
    alert(''Invalid day!'');
    if (mmObj.getMonth(mmObj.setMonth(month)) != month)
    alert(''Invalid month!'');
    if (mmObj.getYear(mmObj.setYear(year)) != year)
    alert(''Invalid year!'');
    </SCRIPT>
    ');

  • How to Clear all the data of open windows form of another exe?

    Hi,
    I want to make utility which will clear all the data from one windows application.
    i know the application name. The application of which data i want to clear is made in C# and contains many windows forms and controls.
    out of that opened windows form and controls inside it need to be cleared.
    Please guide on how to do this in C#?

    Short version: Find the window and send it a message with
    SendMessage.
    Open up Spy++ and find your form's window.  You will see that the window has children and they have classes of the form "WindowsForms10.EDIT.*"  Those are TextBox controls.  You can call things like SetWindowText to set the
    text of the window to clear it.
    To do this programmatically, you'll have to obtain the window hand that corresponds to the control.  You can find windows with
    FindWindowEx or
    EnumWindows.  Locate the window by name or class or whatever else you can determine about it.  Find the child windows and "clear" them however you wish.  I assume you mean to set empty strings to all the TextEdit controls. If you
    intend to do something more sophisticated than that, then you'll have to be more specific about what you mean by "Clear all the data".
    It may or may not be obvious that you'll be poking around with Win32 API calls via PInvoke to accomplish much of this. Example:
    SetWindowText via PInvoke.

  • How do I validate multiple records held in the form?

    I have a form containing a list of records from a base table.
    The records consist of 2 columns, a from and to value. The
    records must specify ranges and those ranges must be in order
    and not overlap. I.e. 1...2, 5...9 NOT 1...4, 3...6. How can I
    ensure this is the case before the user commits any changes to
    the database?
    A When-Validate... trigger doesn't allow me to use built-ins
    like GO-ITEM etc which would allow me to do this. Also these
    triggers will only look at the current record, not the previous
    or next record.
    Any ideas?
    null

    Steve West (guest) wrote:
    : I have a form containing a list of records from a base table.
    : The records consist of 2 columns, a from and to value. The
    : records must specify ranges and those ranges must be in order
    : and not overlap. I.e. 1...2, 5...9 NOT 1...4, 3...6. How can
    I
    : ensure this is the case before the user commits any changes to
    : the database?
    : A When-Validate... trigger doesn't allow me to use built-ins
    : like GO-ITEM etc which would allow me to do this. Also these
    : triggers will only look at the current record, not the previous
    : or next record.
    : Any ideas?
    Hi,
    There is another way to validate each record as and when it is
    created. Create a parameter P1 and created a
    WHEN-VALIDATE-RECORD trigger at block level.. The code I used to
    verify the requirement is follows. Here Col1 is From and Col2 is
    To. You can add more functionalities to it.
    WHEN-VALIDATE-RECORD
    if :col2 is null or (:col2 <= :col1) then
    message(' The numbers should be in order');
    raise form_trigger_failure;
    end if;
    if :parameter.p1 is null then
    :parameter.p1 := :col2;
    else
    if :col1 != :parameter.p1 + 1 then
    message(' The numbers should be in sequence');
    raise form_trigger_failure;
    end if;
    :parameter.p1 := :col2 ;
    end if;
    Hope this will help.
    null

  • How i validate textbox with dynamic name?.

    My form got a dynamic textbox, it may be 0 or 1 or ....10 in
    the form based on user action.
    Before submitting the form, i want to make sure user enter
    value for all textboxs.
    How can i validate the text box?.
    textbox name item_val_#i#
    item_val_1
    item_val_n
    item_val_ may not be present if user is not adding item_val_
    textbox.
    Please send me validation javascript.

    @javagene:
    there are so many things wrong with your code that i am not
    even going
    to bother with listing the errors, especially since Grizzly
    has already
    done such a nice job of it
    just some advice:
    learn the basics, man/woman!
    the code works fine if - just re-write it correctly! i have
    tested it.
    fix all the syntax and logic errors you have in your code and
    it will work.
    tip: learn the syntax/rules of javascript and how call js
    functions from
    element events
    and learn how to nest quotes properly
    and also learn some cf basics, especially the
    <cfoutput> tag...
    and fix your cfif/cfelse logic if you want to see any text
    boxes on the
    page, never mind in increased numbers...
    and while we are at it, learn to read and try out the replies
    to your
    posts instead of just repeating your question / pleading for
    help again
    and again in hope of someone getting tired of it and posting
    the whole
    complete code for you...
    @ian:
    totally agree with your point. now, where do i send my
    invoice to?..

  • How do I validate this ?

    I use the following code to dynamically generate input fields based on the quantity :
    <cfloop from="1" to="#quantity#" index="i">
    <table border="0">
    <tr>
    <td width="33" align="right" class="TitleText"><b>#i#:</b> </td>
    <td width="148" align="right" clsas="TitleText">
    <cfinput type="text" name="serialNumber" size="40">
    <input type="hidden" name="PartNumberID" value="#PartNumberID#"><br></td>
    </tr>
    </table>
    </cfloop>
    The problem I am having is that people purposely blowup the serialNumber field by exceeding the limit size 40. I can use maxlenght to prevent this, but I want to display an error message. How can I do this ?

    If I give it a unique name, like suggested :
    <cfoutput>
    <cfloop from="1" to="#quantity#" index="i">
    <cfinput type="text" name="serialNumber_#i#" size="40">
    </cfloop>
    </cfoutput>
    How do I validate on the client side (javascript ?) to produce an error message ?
    Better yet, how do I insert into a table ? I currently use this code, but the unique rename will change everything :
    <cfloop from="1" to="#listlen(form.serialNumber)#" index="i">
    <cfset col2 = listgetat(form.gfmPartNumberID, i)>
    <cfset col3 = listgetat(form.serialNumber, i)>
        <cfquery name="qryInsertSerial" datasource="test">
        insert into gfmSerialNumbers
        (serialNumberID,
         gfmPartNumberID,
         serialNumber,
         status,
         lineItem,
         closedFlag)
         values
         ('#nextSerialNumberID#',
          '#col2#',
          <cfif col3 is "">
          'None',
          <cfelse>
          '#ucase(col3)#',
          </cfif>
          '1',
          '#i#',
        </cfquery>

  • How to access the datasource window in SSRS for sql server 2008 R2 for writing my query without having to go through the wizard?

    I have used SSRS a lot years ago with Sql Server 2000 and Sql Server 2005. I have written external assemblies, ... But now I have to do this with Sql Server 2008 (R2 -- which I realize I am way behind the times already but ...)  in sql server 2000 and
    2005 there was a tab for datasource to the left of the tab for design which was to the left of the preview tab. How do I get to the datasource window in sql server 2008 (r2) ?
    I see that datasource explorer.  But where can I get to the datasource window to edit my queries and so forth for sql server 2008 (R2)?
    Thanks
    Rich P

    I think I found the answer to my question --- just right-click on the the Data Sources or Datasets for editing connections and dataset queries.  I'm guessing it gets even fancier with Sql Svr 2012 - 2014.    Man, that's the one thing
    about coding platforms -- you let it go for a few years and come back, and everything has changed (well, a lot of things).  Now I need to figure out how to add an external assembly to SSRS 2008 (R2).
    Rich P

  • How do you validate XML file against a Schema?

    Are there free applications that does that?

    Thanks, but how do you validata the Schema itself, which is an XML file.
    I know the schema DTD is online, but still I need some utility to do it
    Thanks

  • How do we validate input fields on the selection screen

    How do we validate input fields on the selection screen

    hi balram,
    u can validate input fields using <b>AT SELECTION-SCREEN</b>  Event.
    PARAMETERS : p_werks TYPE marc-werks.
    AT SELECTION-SCREEN ON p_werks.
    SELECT SINGLE *
    FROM t001w
    WHERE werks = p_werks.
    IF sy-subrc <> 0.
    MESSAGE 'Invalid Plant' TYPE 'I'.
    ENDIF.
    Like this, we can validate user input for plant.
    check this link:
    http://help.sap.com/saphelp_nw04s/helpdata/en/9f/db9a2e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/56/1eb6c705ad11d2952f0000e8353423/content.htm
    Reware me if useful......
    Harimanjesh AN

  • How can I validate my warranty with a refurbished iphone?

    On August 28th I visited Miami and I went to the Apple Store to replace my Iphone 4 broken out of warranty with a Refurbished Iphone.
    The problem is that the refurbished Iphone replacement never worked! I tried to verify my coverage status but it is out of warranty. I know that there are 90 days of warranty. However, how can I validate this warranty because the IMEI is not accepted to chat or contact Apple Support? Somebody can help me?
    Thank you

    SILsam wrote:
    I've already checked it, however the device does not have coverage. It was a refurbished iphone 4 and theoretically it has 90 days of warranty.
    According to your original post, your limited warranty is scheduled to expire on November 28th.  That service replacement warranty was never intended to include live support via chat or phone conversations with an AppleCare advisor.

  • How can we assign Extract Structure of datasource to request to transport

    Hi,
    I was trying to transport datasource. But it ended with errors due to unavailability of extract structure. So plz guide me how I can assign Extract structure of datasource to request to transpport.
    I tried to assign in RSA6 but here there is no option to extract structure to assing to request.

    Hi,
    Normally when you get the screen to select and hide the fileds and then save it, you will get the extract structure collected automaticaly in your TP request.
    Hope it helps
    Regards,
    Srini

  • HOW WE CAN VALIDATE A FIELD THAT SHOULD NOT BE SPECIAL CHARACTER?

    HOW WE CAN VALIDATE A FIELD THAT SHOULD NOT BE SPECIAL CHARACTER?

    data : v_abcde like sy-abcde,
             v_num like '0123456789',
              v_data(60) type c.
    start-of-selection.
    v_abcde = sy-abcde.
    concatenate v_abcde v_num into v_data.
    if ur field co v_data
    else.
    message.
    endif.

  • How the data extraction happens from HR datasources from R/3 to BW system.

    Hello All
    How the data extraction happens from HR datasources from R/3 to BW system.Incase of delta records ( for CATS datasources ) ,Is there any flow like LO .
    Incase of Full and delta loads how does the data will be taken from R/3 to BW,DO we need to fill setup tables ?
    Searched forum but couldnt able to find the relevant one.
    Thankyou
    Shankar

    Hi Shankar.
    HR Datasources do not have setup tables . Though before implementation, certain customizations should be done and the delta loads have dependency on other data sources. Also you must have implemented Support Package SAPKH46C32, or have made the relevant corrections in SAP Note 509592.
    Follow this link for details on customization and dependencies for all CATS datasources.
    http://help.sap.com/saphelp_nw70/helpdata/en/86/1f5f3c0fdea575e10000000a114084/frameset.htm
    Regards,
    Swati

  • How can I configure ang use JNDI datasource on Tomcat 4.0.x ?

    How can I configure ang use JNDI datasource on Tomcat 4.0.x ?
    Please help me , Thanks !

    Hello ,
    You need to go through the JNDI tutorial which you can access at the sun's site. It will explain all the things you need.
    By the way all you want to use JNDI datasource is JNDI class library and some naming or directory service provider, which also you can download from sun.
    Good Luck.

  • How to create multiple TextBox using Visual C# in runtime?

    Hello,
    I am writing the following code to create TextBox programmatically in run time. When I am clicking in the target Button it will create TextBox. But the problem is, only one TextBox is created. Can anyone tell me how can I write code that will create multiple
    TextBox when I am continuously clicking a Button?
    Here is my current code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    namespace testing
    public partial class Form1 : Form
    public Form1()
    InitializeComponent();
    int x, y;
    TextBox txt = new TextBox();
    private void button_add_Click(object sender, EventArgs e)
    cnt++; y = 139; x = 139;
    txt.Parent = this;
    txt.Location = new System.Drawing.Point(x, y);
    txt.Size = new System.Drawing.Size(100, 20);
    txt.Name = "text" + cnt; ;
    txt.Text = "Text" + cnt; ;
    ///txt.Visible = true;
    y += 30; x += 30;
    ///MessageBox.Show(txt.Name.ToString());
    int cnt;
    private void Form1_Load(object sender, EventArgs e)
    cnt = 0; x = 139; y = 139;
    - Thanks

    Hello,
    In your sample code only one instance of the text box is created. You may put the 
    TextBox txt = new TextBox();
    inside the button click handler function for creating new instance for each button click.
    Also change the change  txt.Location  for each text box. In your code it is specified as 139, 139 always.
    Regards,
    Mathews

Maybe you are looking for