Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my web application i have a dropdownlist which get populated by some values from
database. I want if some one have not select any value from dropdownlist and click submit button the it must show alert messege like "you must select value from dropdownlist"
I tired to add conditionblock when user doesnot select values from dropdownlist in button click eventHandler as flows:
XML
System.Text.StringBuilder sbMessage = new StringBuilder();
                sbMessage.Append("<script type=\"text/javascript\">");
                sbMessage.Append("function alertMessage() {");
                sbMessage.Append("alert(\"please select value from dropdownlist\");");
                sbMessage.Append("}");
                sbMessage.Append("</script>");
                this.Page.RegisterClientScriptBlock("alerMessege", sbMessage.ToString());

but this doesnt show alert message can any one help me out here.
Posted
Updated 31-Mar-11 21:51pm
v2

I think it should be

JavaScript
this.Page.RegisterClientScriptBlock(this.GetType(), "alertMessage", sbMessage.ToString());


There is spelling mistake in your code (alerMessege).
 
Share this answer
 
v3
Comments
Raj.rcr 1-Apr-11 3:57am    
But, still it doesn't work...
Wild-Programmer 1-Apr-11 4:04am    
Use it like this

ClientScript.RegisterClientScriptBlock( typeof(Page), "myrest", "<script>alert('Hello');</script>");
Raj.rcr 1-Apr-11 4:19am    
The good one Amit. Hope OP will get help from ur answer.. my 5
Wild-Programmer 1-Apr-11 4:44am    
Thanx Raj
call onButtonClick function on submit button client click--

<script>
function onButtonClick()
{
dropdown=document.getElementById("<%=ddlSelect.ClientID %>")
if(dropdown.selectedIndex<0)
{
alert("Your msg");
return false;
}
return true;

}
</script>


--Pankaj
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900