Pages

Tuesday, 7 January 2014

Call javascript function in C# ,Regex Validation

.CS File:


 string TempstrStockId = ((TextBox)gvStockShifting.Rows[gvStkShiftrow.RowIndex].FindControl("txtStockId")).Text.Trim();
                string regexExp = @"^[0-9]+$";
                Regex regexValid = new Regex(regexExp);
                if (regexValid.IsMatch(TempstrStockId))
                {
                    strStockId = TempstrStockId;
                    
                }else{
                    ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert();", true);                    
                    ((TextBox)gvStockShifting.Rows[gvStkShiftrow.RowIndex].FindControl("txtStockId")).Focus();
                    return;
                }


ASPX File:


<script type="text/javascript">
        function Showalert() {
            alert('Call JavaScript function from codebehind');
        }
    </script>

No comments:

Post a Comment