RadioButtonList、DropDownlist 在客端确认更改

RadioButtonList:
   
   
   
   
<asp:RadioButtonList id="rblMatrixType" style="Z-INDEX: 101; LEFT: 88px; POSITION: absolute; TOP: 104px"
  
  
 runat="server" Width="200px" AutoPostBack="True">
   
   
 <asp:ListItem Value="A" Selected="True">A</asp:ListItem>
   
   
 <asp:ListItem Value="B">B</asp:ListItem>
   
   
</asp:RadioButtonList>
   
   
<script>
   
   
 function attachNewEvent(ctlID)
   
   
 {
   
   
  var ctl = document.all[ctlID];
   
   
  ctl.onclick = "";
   
   
  ctl.attachEvent("onclick", comfirmRBLChange);
   
   
 }
   
   
 
   
   
 function comfirmRBLChange()
   
   
 {
   
   
  if (confirm('Change the type will result in the loss of data. Are you sure you want to proceed?'))
   
   
  {
   
   
   __doPostBack(event.srcElement.id, '');
   
   
  }
   
   
  else
  
  
  {
   
   
   document.all[rblSelectedItem].checked = "checked";
   
   
   return false;
   
   
  }
   
   
 }
   
   
</script>
   
   
protected override void OnPreRender(EventArgs e)
   
   
{
   
   
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
   
   
        sb.Append("<script>" + System.Environment.NewLine);
   
   
        sb.Append(string.Format("       var rbl = /"{0}/";{1}", this.rblMatrixType.ClientID,System.Environment.NewLine));
   
   
        
   
   
        for (int index = 0; index < this.rblMatrixType.Items.Count; index++)
   
   
        {
   
   
               sb.Append(string.Format("       attachNewEvent(rbl + /"_{0}/");{1}",index.ToString(),System.Environment.NewLine));
   
   
               if (this.rblMatrixType.Items[index].Selected)
   
   
               {
   
   
                       sb.Append(string.Format("       var rblSelectedItem = /"{0}_{1}/";{2}",this.rblMatrixType.ClientID,index.ToString(),System.Environment.NewLine));
   
   
               }
   
   
        }
   
   

  
  
   
    
  
  
        sb.Append("</script>" + System.Environment.NewLine);
   
   

  
  
   
    
  
  
        if (!this.Page.IsStartupScriptRegistered("RadioButtonListChangeConfirm"))
   
   
        {
   
   
               this.Page.RegisterStartupScript("RadioButtonListChangeConfirm", sb.ToString());
   
   
        }
   
   

  
  
   
    
  
  
        base.OnPreRender (e);
   
   
}
   
   

  
  
   
    
  
  

  
  
   
    
  
  
DropDownList
   
   
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 280px"
  
  
 runat="server" Width="88px" AutoPostBack="True">
   
   
 <asp:ListItem Selected="True"></asp:ListItem>
   
   
 <asp:ListItem Value="A">A</asp:ListItem>
   
   
 <asp:ListItem Value="B">B</asp:ListItem>
   
   
 <asp:ListItem Value="C">C</asp:ListItem>
   
   
</asp:DropDownList>
   
   
<script>
   
   
 var ddlCtlID = "<%=this.DropDownList1.ClientID%>";
   
   
 
   
   
 function confirmChangeSelectItem(ctl,message)
   
   
 {
   
   
  if (ctl[ctl.oldIndex].innerText == "")
   
   
  {
   
   
   return true;
   
   
  }
   
   
  if (!confirm(message))
   
   
  {
   
   
   ctl.selectedIndex = ctl.oldIndex;
   
   
   return false;
   
   
  }
   
   
  else
  
  
  {
   
   
   return true;
   
   
  }
   
   
 }
   
   
</script>
   
   

  
  
   
    
  
  
protected override void OnPreRender(EventArgs e)
   
   
{
   
   
        this.DropDownList1.Attributes.Add("oldIndex", this.DropDownList1.SelectedIndex.ToString());
   
   
        this.DropDownList1.Attributes.Add("onchange","if (!confirmChangeSelectItem(this,'Change the size category combination will result in the loss of color prepack data. Are you sure you want to proceed?')) return;");
   
   

  
  
   
    
  
  
        base.OnPreRender (e);
   
   
}
   
   

  
  
   
    
  
  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值