Hi Corobori,
Please refer below sample.
HTML
<asp:DropDownList ID="ddlDetails" runat="server">
<asp:ListItem Value="0" Text="--Select Details--"></asp:ListItem>
<asp:ListItem Value="1" Text="ASPSnippets"></asp:ListItem>
<asp:ListItem Value="2" Text="ASPForum"></asp:ListItem>
<asp:ListItem Value="3" Text="Excelasoft Solution"></asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Submit" />
<br />
<asp:Label Text="Invalid" runat="server" ID="lblMesssage" Visible="false"/>
Code
C#
protected void Submit(object sender, EventArgs e)
{
lblMesssage.Visible = false;
if (ddlDetails.SelectedIndex > 0 && !string.IsNullOrEmpty(txtValue.Text))
{
lblMesssage.Visible = true;
return;
}
if (ddlDetails.SelectedIndex == 0 && string.IsNullOrEmpty(txtValue.Text))
{
lblMesssage.Visible = true;
return;
}
}
VB.Net
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
lblMesssage.Visible = False
If ddlDetails.SelectedIndex > 0 AndAlso Not String.IsNullOrEmpty(txtValue.Text) Then
lblMesssage.Visible = True
Return
End If
If ddlDetails.SelectedIndex = 0 AndAlso String.IsNullOrEmpty(txtValue.Text) Then
lblMesssage.Visible = True
Return
End If
End Sub
Screenshot