IT/C#

c# 숫자및 소수점 입력 onkeypress

밤톨순이 2018. 1. 2. 15:48

<td class="td_top_border"><asp:TextBox ID="txtLowTemperatures" CssClass="input01 w50" runat="server" style="text-align:right; ime-mode:disabled;" Text="0" /> ℃</td>

 

 

#region 숫자만 입력되게 처리
            TextBox[] txtboxArray = { txtHecKrDispatch, txtHecKrPJT, txtHecKrFunction, txtHecTnStaff, txtHecTnFunction, txtHecLcStaff, txtHecLcFunction, txtPartnerKr, txtPartnerTn, txtPartnerLc, txtLowTemperatures, txtHeightTemperatures, txtPrecipitation, txtRainFallTime, txtStopWorkTime };
            KeyInputOnlyNumber(txtboxArray);

            TextBox[] txtboxFoaltArray = { txtLowTemperatures, txtHeightTemperatures, txtPrecipitation, txtRainFallTime, txtStopWorkTime };
            KeyInputOnlyFoalt(txtboxFoaltArray);
            #endregion

            if (!IsPostBack)
            {}

 

 

#region 숫자만 입력
    protected void KeyInputOnlyNumber(TextBox[] txtBoxList)
    {
        for (int i = 0; i < txtBoxList.Length; i++)
        {
            txtBoxList[i].Attributes["onkeypress"] = "if( ((event.keyCode < 48 ) || (event.keyCode > 57)) ) { return false; }";
        }
    }

    protected void KeyInputOnlyFoalt(TextBox[] txtBoxList)
    {
        for (int i = 0; i < txtBoxList.Length; i++)
        {
            txtBoxList[i].Attributes["onkeypress"] = "return DemicalNumberCheck(event);";
        }
    }
    #endregion