I need both onchange in javascript and OnSelectedIndexChanged in Asp.Net

Posted by Mohanbabu17 under Regular Expressions on 7/30/2010 | Views : 23287 | Status : [Member] | Replies : 4
Hi Friends,

I have dropdownlist, i need both client side validation and server side. if clientside validation fails, then i should stop my autopostback.

Anybody can help me

<asp:DropDownList ID="ddlSeason" runat="server" CssClass="ctr_ddl" AutoPostBack="true"
onchange="return ddlChkSelect('ddlSeason');"
OnSelectedIndexChanged="LoadKitOnSeason_Change" >
</asp:DropDownList>

function ddlChkSelect(CtlID) {
var ddl = document.getElementById(CtlID);

if (ddl.value == "0") {
return false ;
}
else {
return true;
}

}

Mohan


Responses

Posted by: Neeks on: 7/30/2010 [Member] Bronze

Up
0
Down
Are you getting any error in this code?

You can try

<script type="text/javascript">

function testFunction(obj)
{
//Do the coading
return true; //This will allow the page to get Post and if False it will stop the page

}
</script>

<asp:DropDownList ID="DropDownList1" onchange="javascript:return testFunction(this);" runat="server" AutoPostBack="True">
<asp:ListItem>Test</asp:ListItem>
<asp:ListItem>TEst1</asp:ListItem>
</asp:DropDownList>


Mohanbabu17, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 7/30/2010 [Member] Bronze

Up
0
Down
I think you are missing the AutoPostBack property.
Set the AutoPostBack = True to post the page.

Thanks,

Mohanbabu17, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mohanbabu17 on: 8/2/2010 [Member] Starter

Up
0
Down
No yaar.

This Code works for Button. But Not Working for DropDownList.

May be because we give autopostback true for DDL


Mohan

Mohanbabu17, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vaishali.fresher on: 8/2/2010 [Member] Starter

Up
0
Down
you can do post back using javascript method __doPostBack and call the selectedindexchanged event in this method by passing 2 parameters. first parameter being the dropdownllist id and second parameter being the selectedindexchanged event name of dropdownlist

Mohanbabu17, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response