I need help to restrict my textbox to accept just numbers. I have another textbox event textchanged and in that condition I want to not allow user to write other characters than numbers. have implemented the maxlength but I can't validate to accpet just numbers.
here is my condition that I want to implement in:
Protected Sub txtIdType_TextChanged(sender As Object, e As EventArgs)
Dim txtb As TextBox = CType(FormViewPerson.FindControl("txtIdType"), TextBox)
Dim txtb1 As TextBox = CType(FormViewPerson.FindControl("TextBoxIDCode"), TextBox)
If (txtb.Text = "Leternjoftimi" OrElse txtb.Text = "KosovoIDCard" OrElse txtb.Text = "Licna karta") Then
txtb1.MaxLength = 10
End If
End Sub
You can do this simply in aspx page, like below:-
<asp:TextBox ID="txtNumbers" runat="server" autocomplete="off" ValidationGroup="AddNew"></asp:TextBox>
<asp:RegularExpressionValidator ID="regNumbers" runat="server" ErrorMessage="Only numbers are allowed" ControlToValidate="txtNumbers" ValidationExpression="^[0-9]*$" ValidationGroup="AddNew"></asp:RegularExpressionValidator>
You don't need to use the code-behind for this.
Hope this helps
You can add the validator from code behind. Try to do the following:
Protected Sub txtIdType_TextChanged(sender As Object, e As EventArgs)
Dim txtb As TextBox = CType(FormViewPerson.FindControl("txtIdType"), TextBox)
Dim txtb1 As TextBox = CType(FormViewPerson.FindControl("TextBoxIDCode"), TextBox)
If (txtb.Text = "Leternjoftimi" OrElse txtb.Text = "KosovoIDCard" OrElse txtb.Text = "Licna karta") Then
txtb1.MaxLength = 10
Dim validator As New RegularExpressionValidator()
validator.ID = "validator" + New Random().[Next](100, 1000)
validator.ControlToValidate = CType(FormViewPerson.FindControl("TextBoxIDCode"), TextBox).ID
validator.ValidationExpression="^[0-9]*$"
FormViewPerson.Controls.Add(validator)
End If
End Sub
Suksese!
I solved my problem using this function :
For Each ch As Char In txt.Text
If Not Char.IsDigit(ch) Then
txt.Text = ""
Exit Sub
End If
Next
Related
i am not able to find the id of the update button is thee any way to
find the update button id which is inside the gridview and the grid is
inside the update panel.
Script register is written is page load. i am writing this so as
currently update button is firing on second click
ASPX code
<asp:UpdatePanel ID="UpdatePanelSubMeter" runat="server">
<ContentTemplate>
<EditItemTemplate>
<asp:Button ID="btn_Update" Style="background-color: #B2DE94; width: 40px" CausesValidation="false" runat="server" OnClientClick="return fnCheck(this);" Text="Update" CommandName="Update" />
</EditItemTemplate>
</asp:UpdatePanel>
vb.net code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ErrorLabel.Text = String.Empty
Me.ErrorLabel.Visible = False
Dim pageName = HttpContext.Current.Request.Url.AbsoluteUri
If (Not Page.IsPostBack) Then
tblNAbers.Visible = True
BindBLDGDropDown("adonepudi")
End If
For Each gvr As GridViewRow In GridSubMeter.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim button As Button = CType(gvr.FindControl("btn_Update"), Button)
If Not (button Is Nothing) Then
ScriptManager.GetCurrent(Me).RegisterPostBackControl(button)
end sub
Protected Sub ddlBldgId_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlBldgId.SelectedIndexChanged
If ddlBldgId.SelectedItem.Value != -1 Then
BindGridSubMeter()
end sub
Protected Sub BindGridSubMeter()
Dim conMRI As New ConnectionMRI()
Dim ds As DataSet = conMRI.NabersSubMetergetData(ddlBldgId.SelectedItem.Value, ddlRating.SelectedItem.Value)
TextExclusions.Text = ds.Tables(1).Rows(0).Item(0).ToString()
UpdatePanelExclusions.update()
With GridSubMeter
.DataSource = ds.Tables(0)
.DataBind()
End With
End Sub
Protected Sub GridSubMeter_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridSubMeter.RowEditing
GridSubMeter.EditIndex = e.NewEditIndex
Me.BindGridSubMeter()
End Sub
Protected Sub GridSubmeter_PageIndexChanging(sender As Object, e4 As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridSubMeter.PageIndexChanging
GridSubMeter.PageIndex = e4.NewPageIndex
Me.BindGridSubMeter()
End Sub
Protected Sub GridSubMeter_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridSubMeter.RowUpdating
Dim txtMeterIdn As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txtMeterIdn"), TextBox)
Dim txCTFact As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txCTFact"), TextBox)
Dim txReadStartDate As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txReadStartDate"), TextBox)
Dim txReadEndDate As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txReadEndDate"), TextBox)
Dim txStartKwh As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txStartKwh"), TextBox)
Dim txEndKwh As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txEndKwh"), TextBox)
Dim txBillPer As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txBillPer"), TextBox)
Dim MeterIdn As String = txtMeterIdn.Text.Trim.ToString()
Dim CTFact As Decimal = Convert.ToDecimal(txCTFact.Text)
Dim ReadStartDate As Date = Date.Parse(txReadStartDate.Text)
Dim ReadEndDate As Date = Date.Parse(txReadEndDate.Text)
Dim StartKwh As Decimal = Convert.ToDecimal(txStartKwh.Text)
Dim EndKwh As Decimal = Convert.ToDecimal(txEndKwh.Text)
Dim billper As Decimal = Convert.ToDecimal(txBillPer.Text)
Dim leasid As String = GridSubMeter.Rows(e.RowIndex).Cells(0).Text.Trim.ToString()
Dim suitid As String = GridSubMeter.Rows(e.RowIndex).Cells(1).Text.Trim.ToString()
Dim occupant As String = GridSubMeter.Rows(e.RowIndex).Cells(2).Text.Trim.ToString()
GridSubMeter.EditIndex = -1
Dim conMRI As New ConnectionMRI()
conMRI.NaberSubmeter(ddlBldgId.SelectedItem.Value, leasid, suitid, occupant, MeterIdn, CTFact, ReadStartDate, ReadEndDate, StartKwh, EndKwh, billper)
Me.BindGridSubMeter()
End Sub
Try removing
For Each gvr As GridViewRow In GridSubMeter.Rows
If gvr.RowType = DataControlRowType.DataRow Then
Dim button As Button = CType(gvr.FindControl("btn_Update"), Button)
If Not (button Is Nothing) Then
ScriptManager.GetCurrent(Me).RegisterPostBackControl(button)
from page load and paste it in BindGridSubMeter at the end.
Try this
For Each gr As GridViewRow In Grid_Records.Rows
Dim bt As Button = DirectCast(gr.Cells(0).FindControl("btn_Update"), Button)
Dim here As bt.properties
Next
I have a DetailsView which contains several text boxes and also a DropDownList.
Now, what I want to do is to write an SelectedIndexChanged event for that DropDownList, but my problem is that I cannot reach it anymore/reference it.
If I just put a DropDownList right on the form it´s no problem but now winds it is inside the DetailsView it seems impossible to reach it.
Any suggestions?
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Protected Sub DetailsViewAvtaleInfo_PageIndexChanging1(sender As Object, e As DetailsViewPageEventArgs) Handles DetailsViewAvtaleInfo.PageIndexChanging
Dim DropDownListContractType As DropDownList = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("DropDownListContractType"), DropDownList)
Dim TextBoxLeasingPriceMonth As TextBox = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("TextBoxLeasingPriceMonth"), TextBox)
If DropDownListContractType.Text = "Kjøp" Then
TextBoxLeasingPriceMonth.Visible = False
End If
End Sub
I know this is not right, but its as far as I get. I would want to just Write the code within the following sub but it just will not work:
Protected Sub DropDownListContractType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownListContractType.SelectedIndexChanged
Dim TextBoxLeasingPriceMonth As TextBox = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("TextBoxLeasingPriceMonth"), TextBox)
If DropDownListContractType.Text = "Leasing" Then
TextBoxLeasingPriceMonth.Visible = False
End If
End Sub
You did not post the markup for the dropdownlist, it should be like below (Attached the method to the event):
<asp:DropDownList ID="DropDownListContractType" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownListContractType_SelectedIndexChanged">
<asp:ListItem Text="Kjøp" Value="2"></asp:ListItem>
<asp:ListItem Text="Leasing" Value="1"></asp:ListItem>
</asp:DropDownList>
Your code also have some issues:
Should be DropDownList.SelectedItem.Text instead of
DropDownList.Text.
You have to cast the sender to DropDownList in DropDownListContractType_SelectedIndexChanged method.
You have to find the NamingContainer of DropDownList in DropDownListContractType_SelectedIndexChanged method
If you have the following code, it should work:
Protected Sub DropDownListContractType_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim DropDownListContractType As DropDownList = DirectCast(sender, DropDownList)
Dim TextBoxLeasingPriceMonth As TextBox = DirectCast(DropDownListContractType.NamingContainer.FindControl("TextBoxLeasingPriceMonth"), TextBox)
If DropDownListContractType.SelectedItem.Text = "Leasing" Then
TextBoxLeasingPriceMonth.Visible = False
End If
End Sub
Protected Sub DetailsViewAvtaleInfo_PageIndexChanging(sender As Object, e As DetailsViewPageEventArgs) Handles DetailsViewAvtaleInfo.PageIndexChanging
Dim DropDownListContractType As DropDownList = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("DropDownListContractType"), DropDownList)
Dim TextBoxLeasingPriceMonth As TextBox = DirectCast(Me.DetailsViewAvtaleInfo.FindControl("TextBoxLeasingPriceMonth"), TextBox)
If DropDownListContractType.SelectedItem.Text = "Kjøp" Then
TextBoxLeasingPriceMonth.Visible = False
End If
End Sub
I have tested the code above. If you have any issue, try to copy/paste the markup and code.
You can download my test project to compare with yours here.
I've been battling with this issue for a couple of days now and would really appreciate if someone would shed some light for me.
I am populating a dropdownlist based on the selection from another dorpdownlist. As long as there is no postback happening, I see the list getting populated correctly but after a postback, my dropdownlist is empty.
At first, I was trying to manually set the Text property of the ddl but it kept giving me the following error:
System.ArgumentOutOfRangeException: ..ddl has a SelectedValue which is invalid because it does not exist in the list
Then I read somewhere that I need to set the DataValueField property instead so I did that which got rid of the error but now I see the empty dll after a postback.
The ViewStateMode for the ddl is set to Enabled.
The two ddls I'm referring to are defined in a Formview in my .aspx file as ddlCompanyBuyerNVListInsert and ddlCompanyNameListInsert(I'm listing the Insert mode only).
Based on the selections made in ddlCompanyBuyerNVList, I'm populating ddlCompanyNameList.
Here's the code behind for Page_Load and the functions that populate ddlCompanyNameList.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If NavHelper.User.UserName = "" Then
Dim UserIP As String
Dim UserLogin As String
Dim UserEmail As String
UserIP = HttpContext.Current.Request.UserHostAddress
UserLogin = HttpContext.Current.Session("Username")
UserEmail = HttpContext.Current.Session("Email")
GetUserInfo()
CurrentRFQ = Nothing
If NavHelper.RFQ.ID = -1 Then
formview_RFQ.ChangeMode(FormViewMode.Insert)
tabpanelCustomerParts.Visible = False
tabpanelDocuments.Visible = False
tabpanelReviews.Visible = False
tabpanelRFQReviewHistory.Visible = False
listview_CustomerParts.Dispose()
Else
formview_RFQ.ChangeMode(FormViewMode.Edit)
listview_ReviewContracts_Initial.EditIndex = 0
SessionHelper.CurrentObject = TAA.Library.RFQ.GetObject(NavHelper.RFQ.ID)
mRFQ = DirectCast(SessionHelper.CurrentObject, TAA.Library.RFQ)
Dim UserdeptTotal As Long
UserdeptTotal = HttpContext.Current.Session("DepartmentTotal")
If formview_RFQ.FindControl("ddlCompanyBuyerNVList") IsNot Nothing Then
Dim ddl As DropDownList = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVList"), DropDownList)
FillCompanyNameDropDownList(ddl)
End If
tabpanelCustomerParts.Visible = True
tabpanelDocuments.Visible = True
tabpanelReviews.Visible = True
tabpanelRFQReviewHistory.Visible = True
If NavHelper.RFQ.Copy = True Then
SetModifyCopy()
End If
End If
Else 'IsPostBack
datasource_BuyerNVList.Dispose()
datasource_RFQ.DataBind()
datasource_RFQNote.DataBind()
Dim ddl As DropDownList
If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then
ddl = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVListInsert"), DropDownList)
ElseIf formview_RFQ.FindControl("ddlCompanyBuyerNVList") IsNot Nothing Then
ddl = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVList"), DropDownList)
End If
FillCompanyNameDropDownList(ddl)
End If
End If
End Sub
Protected Sub FillCompanyNameDropDownList(ddlCompanyBuyerNamesList As DropDownList)
Try
Using cn As New SqlClient.SqlConnection(DB.RFQconnection)
cn.Open()
Using cm As SqlClient.SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.StoredProcedure
cm.CommandText = "GetCompanyNamesForThisBuyer"
cm.Parameters.AddWithValue("#BuyerName", (ddlCompanyBuyerNamesList.SelectedItem.Text))
Dim ddlCompanyNamesList As DropDownList
If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then
ddlCompanyNamesList = DirectCast(formview_RFQ.FindControl("ddlCompanyNameListInsert"), DropDownList)
Else
ddlCompanyNamesList = DirectCast(formview_RFQ.FindControl("ddlCompanyNameList"), DropDownList)
End If
Using r As New SCF.Data.SafeDataReader(cm.ExecuteReader)
ddlCompanyNamesList.Items.Clear()
ddlCompanyNamesList.Items.Add(New ListItem("Select Company"))
While r.Read
Dim li As ListItem = New ListItem()
li.Value = SCF.Data.SafeData.SafeInteger(r("CompanyBuyerId"))
li.Text = SCF.Data.SafeData.SafeString(r("CompanyName"))
ddlCompanyNamesList.Items.Add(li)
End While
End Using
cm.Dispose()
cn.Close()
' if more than one entry found, clear the company info fields until a selection is made
If ddlCompanyNamesList.Items.Count > 2 Then 'because we've added a "Select Company" as the first item
ClearCompanyInfoFields() ' company fields are text boxes that get cleared here
ddlCompanyNamesList.SelectedIndex = 0
End If
ddlCompanyNamesList.Enabled = True
If ddlCompanyNamesList.Items.Count = 2 Then ' if only one entry found populate the compny info with that one entry's selection
ddlCompanyNamesList.SelectedIndex = 1
FillCompanyInfoFields(ddlCompanyNamesList)
ElseIf ddlCompanyNamesList.Items.Count = 0 Then ' if nothing found use the buyer list to populate company info fields
ddlCompanyNamesList.Items.Clear()
FillCompanyInfoFields(ddlCompanyBuyerNamesList)
ddlCompanyNamesList.Enabled = False
End If
End Using
End Using
Catch ex As System.Exception
SetErrorPanel("An error occured during FillCompanyNameDropDownList.")
Dim err As New HealthMonitoringCustomEvents.ErrorEvent("An error occured during FillCompanyNameDropDownList", Me, ex)
err.Raise()
End Try
End Sub
Protected Sub FillCompanyInfoFields(ddl As DropDownList)
Try
Dim buyerTitle As TextBox
Dim buyerEmail As TextBox
Dim buyerPhone As TextBox
Dim buyerExt As TextBox
Dim buyerMobile As TextBox
Dim buyerFax As TextBox
Dim CoAddr As TextBox
Dim CoCity As TextBox
Dim CoState As TextBox
Dim CoZip As TextBox
If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then
buyerTitle = DirectCast(formview_RFQ.FindControl("txtBuyerTitleInsert"), TextBox)
buyerEmail = DirectCast(formview_RFQ.FindControl("txtBuyerEmailInsert"), TextBox)
buyerPhone = DirectCast(formview_RFQ.FindControl("txtBuyerPhoneNumberInsert"), TextBox)
buyerExt = DirectCast(formview_RFQ.FindControl("txtExtInsert"), TextBox)
buyerMobile = DirectCast(formview_RFQ.FindControl("txtBuyerMobileNumberInsert"), TextBox)
buyerFax = DirectCast(formview_RFQ.FindControl("txtBuyerFaxNumberInsert"), TextBox)
CoAddr = DirectCast(formview_RFQ.FindControl("txtCompanyAddressInsert"), TextBox)
CoCity = DirectCast(formview_RFQ.FindControl("txtCompanyCityInsert"), TextBox)
CoState = DirectCast(formview_RFQ.FindControl("txtCompanyStateCodeInsert"), TextBox)
CoZip = DirectCast(formview_RFQ.FindControl("txtCompanyZipCodeInsert"), TextBox)
Else
buyerTitle = DirectCast(formview_RFQ.FindControl("txtBuyerTitle"), TextBox)
buyerEmail = DirectCast(formview_RFQ.FindControl("txtBuyerEmail"), TextBox)
buyerPhone = DirectCast(formview_RFQ.FindControl("txtBuyerPhoneNumber"), TextBox)
buyerExt = DirectCast(formview_RFQ.FindControl("txtExt"), TextBox)
buyerMobile = DirectCast(formview_RFQ.FindControl("txtBuyerMobileNumber"), TextBox)
buyerFax = DirectCast(formview_RFQ.FindControl("txtBuyerFaxNumber"), TextBox)
CoAddr = DirectCast(formview_RFQ.FindControl("txtCompanyAddress"), TextBox)
CoCity = DirectCast(formview_RFQ.FindControl("txtCompanyCity"), TextBox)
CoState = DirectCast(formview_RFQ.FindControl("txtCompanyStateCode"), TextBox)
CoZip = DirectCast(formview_RFQ.FindControl("txtCompanyZipCode"), TextBox)
End If
Using cn As New SqlClient.SqlConnection(DB.RFQconnection)
cn.Open()
Using cm As SqlClient.SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.StoredProcedure
cm.CommandText = "GetBuyerCompanyInfo"
cm.Parameters.AddWithValue("#companyBuyerId", (ddl.SelectedValue))
Using r As New SCF.Data.SafeDataReader(cm.ExecuteReader)
' populate company information fields in CurrentRFQ
While r.Read
CurrentRFQ.CompanyID = SCF.Data.SafeData.SafeString(r(0))
CurrentRFQ.CompanyBuyerId = SCF.Data.SafeData.SafeString(r(7))
ddl.DataValueField = SCF.Data.SafeData.SafeString(r(1))
CoAddr.Text = SCF.Data.SafeData.SafeString(r(2))
CoCity.Text = SCF.Data.SafeData.SafeString(r(4))
CoState.Text = SCF.Data.SafeData.SafeString(r(5))
CoZip.Text = SCF.Data.SafeData.SafeString(r(6))
buyerTitle.Text = SCF.Data.SafeData.SafeString(r(9))
buyerEmail.Text = SCF.Data.SafeData.SafeString(r(10))
buyerPhone.Text = SCF.Data.SafeData.SafeString(r(11))
buyerExt.Text = SCF.Data.SafeData.SafeString(r(12))
buyerMobile.Text = SCF.Data.SafeData.SafeString(r(13))
buyerFax.Text = SCF.Data.SafeData.SafeString(r(14))
End While
End Using
cm.Dispose()
cn.Close()
End Using
End Using
Catch ex As System.Exception
SetErrorPanel("An error occured during FillCompanyInfoFields.")
Dim err As New HealthMonitoringCustomEvents.ErrorEvent("An error occured during FillCompanyInfoFields", Me, ex)
err.Raise()
End Try
End Sub
And here's how the two ddls are defined in the .aspx file.
<td> <asp:DropDownList ID="ddlCompanyBuyerNVListInsert" runat="server"
AppendDataBoundItems="true" AutoPostBack="true" CssClass="Input"
DataSourceID="datasource_BuyerNVlist" DataTextField="Key" DataValueField="Value"
OnSelectedIndexChanged="ddlCompanyBuyerNVListInsert_SelectedIndexChanged"
ViewStateMode="Enabled" Width="205px"> <asp:ListItem Selected="True" Text="Select
Buyer" Value="0" /> </asp:DropDownList> </td> <td></td> <td class="style4"> Company:
</td> <td>
<asp:DropDownList ID="ddlCompanyNameListInsert" runat="server"
AppendDataBoundItems="True" AutoPostBack="True" CssClass="Input"onselectedindexchanged="ddlCompanyNameListInsert_SelectedIndexChanged"
ViewStateMode="Enabled" Enabled="False"> </asp:DropDownList> </td>
Thank you so much for your response.
After the DetailsView is updated and clicked the Update Command button on the DetailView; I want to set one of the fields to “Complete”. What am I doing wrong here? Pls. help.
here is my code behind:
Protected Sub Test(sender As Object, e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
If IsPostBack Then
Dim TextBox7 As TextBox = TryCast(DetailsView1.Rows(0).Cells(0).FindControl("TextBox7"), TextBox)
TextBox7.Text = "Complete"
End If
End Sub
I have used this method and got it to work.
Protected Sub PageDetailsView_ItemCommand(sender As Object, e As DetailsViewCommandEventArgs)
If Me.PageDetailsView.DefaultMode = DetailsViewMode.[ReadOnly] Then
If e.CommandName.Equals("GenerateModifiedDate", StringComparison.CurrentCultureIgnoreCase) Then
Dim modifiedDateLabel As Label = TryCast(Me.PageDetailsView.FindControl("ModifiedDateLabel"), Label)
modifiedDateLabel.Text = DateTime.Now.ToString()
End If
Else
If e.CommandName.Equals("GenerateModifiedDate", StringComparison.CurrentCultureIgnoreCase) Then
Dim modifiedDateTextbox As TextBox = TryCast(Me.PageDetailsView.FindControl("ModifiedDateTextbox"), TextBox)
modifiedDateTextbox.Text = DateTime.Now.ToString()
End If
End If
End Sub
I have a question related to asp.net and vb.net. I have a repeater control that I bind some data to and allow users to update/change fields within certain text boxes. I added a validation control to trigger when the user doesn't enter a valid date or the text "TBD". On submit, I want to go through and highlight each field where its corresponding validator is not valid. This is my current code, but I am lost as to how to find the text box control.
Sub ValidateDateField(ByVal sender As Object, _
ByVal args As ServerValidateEventArgs)
'validate against three conditions - date, "TBD", and "N/A"
Dim dtValue = args.Value
If dtValue.ToUpper = "TBD" Or dtValue.ToUpper = "N/A" Then
args.IsValid = True
ElseIf IsDate(dtValue) Then
args.IsValid = True
Else
args.IsValid = False
Dim cont As WebControl = DirectCast(Page.FindControl(args.ToString), WebControl)
cont.BackColor = Drawing.Color.White
util.Client_Alert("Please Update Highlighted Fields")
End If
End Sub
I am completely lost as to how to get cont = textbox1row1 of my repeater control. Please advise. All examples I have seen so far directly state the control as in text1.BackColor =
So I figured out the answer. Sorry for the question. Don't know why I didn't think about it sooner. I found the naming container of the my custom val and then found the control based on its name in the repeater. in vb.net it was something like this:
Sub ValidateDateField(ByVal sender As Object, _
ByVal args As ServerValidateEventArgs)
'args holds value. validate against three conditions - date, "TBD", and "N/A"
Dim dtValue = args.Value
Dim cont As CustomValidator = sender
Dim myNC As Control = cont.NamingContainer
Dim strControl As String
strControl = cont.ControlToValidate
Dim txtbox As TextBox = _
DirectCast(myNC.FindControl(cont.ControlToValidate), TextBox)
If dtValue.ToUpper = "TBD" Or dtValue.ToUpper = "N/A" Or IsDate(dtValue) Then
args.IsValid = True
txtbox.BackColor = Drawing.Color.Empty
Else
args.IsValid = False
txtbox.BackColor = Drawing.Color.White
End If
End Sub