JS动态添加按钮客户端事件

gameboyerik001 2010-12-22 09:52:45
小弟想根据 Dropdownlist的选择的值 让 一个保存按钮提示 return confirm('')


就是当 dropdownlist 选择空的时候 保存按钮Btn_Add就添加上 return confirm('确认不选择该选项?')

如果 dropdownlist选择不为空的时候 保存按钮就不提示 直接激发客户端事件就行了

请问应该如何实现?
...全文
115 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq346127416 2010-12-22
  • 打赏
  • 举报
回复
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="11" Value=""></asp:ListItem>
<asp:ListItem Text="12" Value="12"></asp:ListItem>
<asp:ListItem Text="13" Value="23"></asp:ListItem>
<asp:ListItem Text="14" Value=""></asp:ListItem>
<asp:ListItem Text="15" Value=""></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" />



protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DropDownList1.AutoPostBack = true;
if (DropDownList1.SelectedValue == "")
{
Button1.Attributes.Add("onclick", "return confirm('空?');");
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "")
{
Button1.Attributes.Add("onclick", "return confirm('空?');");
}
else
{
Button1.Attributes.Clear();
}
}
Rock870210 2010-12-22
  • 打赏
  • 举报
回复
Rock870210 2010-12-22
  • 打赏
  • 举报
回复
错了,msg应该是onclick
Rock870210 2010-12-22
  • 打赏
  • 举报
回复
if(ddlOrg.SelectedValue == "")
btnAddConts.Attributes.Add("msg", "return confirm('确定不选择?')");
else
{
btnAddConts.Attributes.Remove("msg");
}

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧