使用JavaScript的下拉列表 [英] Dropdownlist with javascript
问题描述
在我的Web应用程序中,我有一个下拉列表,其中填充了
中的一些值
数据库.我想如果某个人没有从dropdownlist中选择任何值,然后单击Submit按钮,它必须显示警报信息,例如您必须从dropdownlist中选择值"
当用户没有从按钮单击事件处理程序的下拉列表中选择值作为流时,我很累于添加conditionblock:
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:
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.
推荐答案
我认为应该是
I think it should be
this.Page.RegisterClientScriptBlock(this.GetType(), "alertMessage", sbMessage.ToString());
您的代码(alerMessege)中存在拼写错误.
There is spelling mistake in your code (alerMessege).
在提交按钮客户端单击时调用onButtonClick函数-
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
--Pankaj
这篇关于使用JavaScript的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!