Validation Control
-
Hi there I'm working whit Visual Studio 2005 developing an ASP.NET 2.0 WebPage I have a DropDownList Control with 2 options to select. I want to generate a validation message according to the selection made in the DropDownList Control. Any ideas??? THANX ¡¡
-
Hi there I'm working whit Visual Studio 2005 developing an ASP.NET 2.0 WebPage I have a DropDownList Control with 2 options to select. I want to generate a validation message according to the selection made in the DropDownList Control. Any ideas??? THANX ¡¡
-
Server-side please
-
Server-side please
Sub DropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList.SelectedIndexChanged Dim script As String = "" Dim ctrl As DropDownList = CType(sender, DropDownList) If ctrl.SelectedValue = "something" Then ' Some Kinda Validation occurs script = "alert('This is what was selected: " & ctrl.SelectedValue & "');" Else ' Some Kinda Validation occurs script = "alert('This is what was selected: " & ctrl.SelectedValue & "');" End If Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "Alert", script, True) End Sub
Is this what you had in mind? -
Sub DropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList.SelectedIndexChanged Dim script As String = "" Dim ctrl As DropDownList = CType(sender, DropDownList) If ctrl.SelectedValue = "something" Then ' Some Kinda Validation occurs script = "alert('This is what was selected: " & ctrl.SelectedValue & "');" Else ' Some Kinda Validation occurs script = "alert('This is what was selected: " & ctrl.SelectedValue & "');" End If Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "Alert", script, True) End Sub
Is this what you had in mind?just an fyi- make sure you provide the html control name when incorporating it within the script string... server controls sometimes take a different name once the result page is sent from the server back to the client. Now, why would anyone be interested in server-side validation? Postbacks are very inefficient! To validate without making round trips to the server, look into using validation controls such as RegularExpression or CompareValidator. Nila Fridley