摘要:FindControl-給初始值/數字驗證/focus
@給初始值 (arraylist把欄位ID放入 , Foreach 跑)
Public Sub SetDefultValue(ByVal a As ArrayList)
Dim txt As New TextBox
For Each texta In a
txt = Me.Master.FindControl("ContentPlaceHolder1").FindControl(texta)
txt.Text = 0
Next
End Sub
@數字欄位驗證+focus欄位 (清空value 回傳ture/false)
Public Function cheaktxtbox(ByVal a As ArrayList) As Boolean
Dim text As TextBox
For Each testa In a
text = Me.Master.FindControl("ContentPlaceHolder1").FindControl(testa)
If Not String.IsNullOrEmpty(text.Text.Trim) Then
If Not IsNumeric(text.Text) Then
ShowMessage(Me, UpdatePanel1, "請輸入數字!")
text.Text = ""
ScriptManager.RegisterStartupScript(Me.Page, UpdatePanel2.GetType(), "focus", String.Format("document.getElementById('{0}').focus()", text.ClientID), True)
Return False
End If
Else
ShowMessage(Me, UpdatePanel1, "數字欄位請勿空白!")
Return False
End If
Next
Return True
End Function
@C#
Control text;
text = this.Master.FindControl("ContentPlaceHolder1").FindControl("txtCompID");
ScriptManager.RegisterStartupScript(this, UpdatePanel2.GetType(), "focus", String.Format("document.getElementById('{0}').focus()", text.ClientID), true);