Friday, May 31, 2013

Form validation Using JQuery

To do form validation using JQuery you can follow the following steps:

1.down load JQuery file from http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
   add this file to your project or refer the above link in master page
    < script src="Scripts/jquery-1.4.1.min.js" type="text/javascript" / >
2.write css file add this file your application.    
     < link href="CSS/Insitecss.css" rel="stylesheet" type="text/css" />;

3.write the bellow code in separate file and add this in master page
        < script src="Scripts/Test.js" type="text/javascript"/ >
   $(document).ready(function () {

   // key up function is used to validate the control data at the time of entering

    $(".onlynumbers").keyup(function (e) {
        this.value = this.value.replace(/[^0-9 ]/g, "")
    });
    $(".onlychars").keyup(function (e) {
        this.value = this.value.replace(/[^A-Z]/g, "");
    });

    var arrmessage = new Array();
    arrmessage[0] = "required field";
    arrmessage[1] = "Select";

    $('.btn-submit').click(function (e) {
       
      // get current form
        var $formid = $(this).parents('form');      
        var status = true;
        $('.required', $formid).each(function () {
            // validate the all mandatory fields
            var InputValue = $(this).val();
            if ($(this).hasClass('txtbox') == true) {
                if (InputValue == "" || InputValue == null || InputValue == "required field") {
                    $(this).val(arrmessage[0]);
                    $(this).addClass('error');
                    status = false;
                }
            }
        });

        if (!status) {
           // if any one of the mandatory field is not entered the page is not submitted to server 
            e.preventDefault();
        }
    });

    $(".required").focus(function () {
         // whereever user click on the mandatory field it clears the error messages 
        $(this).removeClass("error");
        var $val = $(this).val();
        if (jQuery.inArray($val, arrmessage) > -1) {
            $(this).val("");
        }
    });

});

4.give css classes to your web page controls as follows
5.asp.net page design as follows



&lttable&gt
            <tr>
              
                <td>
                   <asp:TextBox ID="TextBox1" runat="server" CssClass="required txtbox onlynumbers"></asp:TextBox>
                </td>
            </tr>

            <tr>
              
                <td>
                   <asp:TextBox ID="TextBox2" runat="server" CssClass="required txtbox onlychars"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                     </td>
                <td>
                    <asp:Button ID="Button1" CssClass="btn-submit" runat="server" Text="Button"
                        onclick="Button1_Click" />
                </td>
            </tr>
           

        </table>

  check this code working fine.


Sunday, May 19, 2013

Want to Code?


Want to Code?
Have I done?
1. Use Case properly documented
2. All Requirements Captured
3. GUI captures all Scenarios
4. Schema Address all requirements
5. My Design
o Is Documented
o Covers All requirements
o Covers All Schemas
o MACDR(Modify, Add, Create, Delete and Report)
o Has No open Items
6. Validate Design Using SP
7. Confident of Coding in 4 hours
o No go to Step1
o Yes proceed for coding
8. Coding 4 hours
9. Unit Testing
10. Defects <4 hours go to step7
> go to step 1
= 0 check in
--enjoy the day
Unit Testing:
1. All fields
o Spelling
o Grammar
o Alignments
o Types
o Restrictions
o Validations
2. Mandatory fields
3. JavaScript validations
4. Reset
o Clear
o Focus
5. Submit
o Error message
o Success message
6. Browser compatibility
7. Tabbing order
8. Entry using keyboard
9. Valid data input
10. Invalid input
11. Look and Feel
---Every tested no defects ----Great Job

Saturday, May 18, 2013

Find dynamic controls ids in .net using recursive method

recursive method : public Control FindControlRecursive(Control control, string ctrlId) { Control returnControl = control.FindControl(ctrlId); if (returnControl == null) { foreach (Control child in control.Controls) { returnControl = FindControlRecursive(child, ctrlId); if (returnControl != null && returnControl.ID == ctrlId) { return returnControl; } } } return returnControl; } Call above method where you want find the contol in asp page. Calling:

Set field Value:

 protected void SetFieldValue(DataTable dsFields) { for (int i = 0; i < dsFields.Rows.Count; i++) { TextBox txt = (TextBox)FindControlRecursive(this, "txt_" + Convert.ToString(dsFields.Rows[i]["field_id"])); if (txt != null) { txt.Text = Convert.ToString(dsApprovalFields.Rows[i]["field_data]"); } } }

 Get the field value:

   TextBox txt = (TextBox)FindControlRecursive(this, "txt_" + Convert.ToString(dt.Rows[i][field_id]));
                         

Monday, May 13, 2013

Get parent controls values in the child gridview

write following code in child RowCommand :
----------------------------------------------------
GridView gv = (GridView)sender;
HiddenField hdbatch_name = (HiddenField)gv.Parent.FindControl("hbbatch");
HiddenField hdcourse_name = (HiddenField)gv.Parent.FindControl("hdcourse");