Hi Suresh,
Please try the following:
*** First my HTML
<HTML>
<HEAD>
<title>DropDownValid</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
<!--
function DropChange(eventTarget, eventArgument) {
if (typeof(Page_ClientValidate) == 'function')
{
Page_ClientValidate();
if (Page_IsValid)
__doPostBack(eventTarget,eventArgument);
return Page_IsValid;
}
else
{
__doPostBack(eventTarget,eventArgument);
return true;
}
}
//-->
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp
ropDownList id="DropDownList1" runat="server"></asp
ropDownList>
<asp:LinkButton id="LinkButton1" runat="server">test</asp:LinkButton>
</form>
</body>
</HTML>
*** My code-behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DropDownList1.Items.Add("a")
DropDownList1.Items.Add("b")
DropDownList1.Items.Add("c")
DropDownList1.Attributes.Add("onchange", "return
DropChange('DropDownList1', '');")
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Response.Write("the index changed")
End Sub
*** How it works
- The link button causes validation & works normally.
- The drop list only posts if the page is valid.
- The code-behind DropDownList1_SelectedIndexChanged event correctly fires
because we pass the correct argument to __doPostBack.
- Notice that I set the drop list's AutoPostBack to false. That is because
AutoPostBack creates an onchange event for the drop list which might
interfere with our onchange event code. Further, our code includes the
functionality of the code that AutoPostBack would have added.
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------