asp.net中ListBox在jQuery中遇到的问题——直接传值到不了后台

简介:
 

<%@ Page Title="" Language="C#" MasterPageFile="~/Manager.Master" CodeBehind="ManagerSendMessage.aspx.cs" Inherits="TeacherFiles.ManagerSendMessage" EnableEventValidation="false"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderContent" runat="server">

<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
     
        $(document).ready(function(){
              
             var lstboxAllTeachersID = "#"+'<%=lstboxAllTeachers.ClientID%>';
             var lstboxSelectdTeachersID="#"+'<%=lstboxSelectdTeachers.ClientID%>';
             var imabtnSendMessageID="#"+'<%=imabtnSendMessage.ClientID%>';
             var hiddenFileID="#"+'<%=HiddenField1.ClientID%>';
             $('fieldset ul li img').click(function(){
           
                var options;
                var remove;
              
                // 把选择项追加给对方
                if($(this).attr("alt")=="arrowAdd")
                {
                    options= $(lstboxAllTeachersID+" option:selected");                 
                    remove=options.remove();
                    remove.appendTo(lstboxSelectdTeachersID);
                }
               
                // 把选择项退回给对方
                if($(this).attr("alt")=="arrowDelete")
                {
                    options=$(lstboxSelectdTeachersID+" option:selected");
                    remove=options.remove();
                    remove.appendTo(lstboxAllTeachersID);
                }
               
                // 把全部追加给对方
                if($(this).attr("alt")=="selectAll")
                {
                    options=$(lstboxAllTeachersID+' option');
                    remove=options.remove();
                    remove.appendTo(lstboxSelectdTeachersID);
                   
                }
               
                // 把全部项退回给对方
                if($(this).attr("alt")=="Reset")
                {
                    options=$(lstboxSelectdTeachersID+' option');
                    remove=options.remove();
                    remove.appendTo(lstboxAllTeachersID);
                }                                   
               
            });
           
            // 获取教师工号
           
function getSeletedTeacherNum()
            {
                var lstStaffs = document.getElementById('<%=lstboxSelectdTeachers.ClientID%>');
                var strStaffs = "";
                for (var i = 0; i < lstStaffs.options.length; i++) {
                    strStaffs +=lstStaffs.options[i].value+",";
                }
               
                $(hiddenFileID).val(strStaffs);
            } 

            // 当点击发送按钮
            $(imabtnSendMessageID).click(function(){
                getSeletedTeacherNum()
            });
    
        });
    </script>
    <form>
<fieldset class="fieldset">

    <legend class="legend">选择需要得到通知的教师</legend>
    <ul>
        <li>
     
            <span>
                   <asp:ListBox ID="lstboxAllTeachers" runat="server"

                        CssClass="listbox"></asp:ListBox>
            </span>
            <img src="images/ArrowAdd.jpg" alt="arrowAdd" class="imagarrowAdd" />
            <img src="images/ArrowDelete.jpg" alt="arrowDelete" class="imagarrowDelete" />
           
            <span><asp:ListBox ID="lstboxSelectdTeachers" runat="server"

                      CssClass="listbox"></asp:ListBox></span>
           
<asp:HiddenField ID="HiddenField1" runat="server"/>
            
        </li>
        <li>
            <span>
                <img src="images/selectAll.jpg" alt="selectAll" />
            </span>
            <span>
                <img src="images/Reset.jpg" alt="Reset" />
            </span>
        </li>
    </ul>
</fieldset>

<br />

<fieldset class="fieldset">
    <legend class="legend">需要发送的消息</legend>
    <ul>
        <li>
            <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Width="380px"

                Height="180px" CssClass="txtbox"></asp:TextBox>
        </li>
        <li>
             <span>
                <asp:ImageButton ID="imabtnSendMessage" runat="server"
                ImageUrl="~/images/SendMessage.jpg" onclick="imabtnSendMessage_Click"/>
            </span>
            <span>
               
                <asp:ImageButton ID="imagbtnResetContent" runat="server"
                 ImageUrl="~/images/Reset.jpg" onclick="imagbtnResetContenet_Click"/>
            </span>
        </li>
    </ul>
</fieldset>

</asp:Content>

 

 

后台

 public partial class ManagerSendMessage : BasePage
    {
        ITeacher newIteacher = new TeacherService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindListBoxAllTeachers();
            }
        }

        public void BindListBoxAllTeachers()
        {
            this.lstboxAllTeachers.DataSource = newIteacher.ReadAllTeacher();
            this.lstboxAllTeachers.DataTextField = "TeacherName";
            this.lstboxAllTeachers.DataValueField = "TeacherNum";
            this.lstboxAllTeachers.DataBind();
        }

        List<string> AllSelectedTeahcerNum = new List<string>();
      
        // 得到选择的教师工号
        public void SendSelectedTeahcerMessage(string[] singleNums)
        {
            for (int i = 0; i < singleNums.Count()-1; i++)
            {
                newIteacher.InsertReceiveMessage(singleNums[i].ToString(), this.txtContent.Text);
                PageExtension.Alert(this, "发布成功!");
            }
        }

        // 发送通知消息给选定的教师,
        protected void imabtnSendMessage_Click(object sender, ImageClickEventArgs e)
        {
           
string AllTheNum = this.HiddenField1.Value;
            string[] singleNums = AllTheNum.Split(',');
            SendSelectedTeahcerMessage(singleNums);
        }

        // 重置发送内容
        protected void imagbtnResetContenet_Click(object sender, ImageClickEventArgs e)
        {
            this.txtContent.Text = "";
        }
    }

目录
相关文章
|
7月前
|
开发框架 前端开发 JavaScript
盘点72个ASP.NET Core源码Net爱好者不容错过
盘点72个ASP.NET Core源码Net爱好者不容错过
172 0
|
7月前
|
开发框架 .NET
ASP.NET Core NET7 增加session的方法
ASP.NET Core NET7 增加session的方法
95 0
|
7月前
|
开发框架 JSON JavaScript
ASP.NET Core3.1实战教程---基于Jquery单文件上传
ASP.NET Core3.1实战教程---基于Jquery单文件上传
86 0
|
存储 开发框架 前端开发
asp.net与asp.net优缺点及示例
asp.net与asp.net优缺点及示例
110 0
|
2月前
|
监控 网络安全 调度
Quartz.Net整合NetCore3.1,部署到IIS服务器上后台定时Job不被调度的解决方案
解决Quartz.NET在.NET Core 3.1应用中部署到IIS服务器上不被调度的问题,通常需要综合考虑应用配置、IIS设置、日志分析等多个方面。采用上述策略,结合细致的测试和监控,可以有效地提高定时任务的稳定性和可靠性。在实施任何更改后,务必进行充分的测试,以验证问题是否得到解决,并监控生产环境的表现,确保长期稳定性。
94 1
|
4月前
|
开发框架 JSON .NET
ASP.NET Core 标识(Identity)框架系列(三):在 ASP.NET Core Web API 项目中使用标识(Identity)框架进行身份验证
ASP.NET Core 标识(Identity)框架系列(三):在 ASP.NET Core Web API 项目中使用标识(Identity)框架进行身份验证
|
4月前
|
开发框架 .NET 数据库连接
ASP.NET Core 标识(Identity)框架系列(一):如何使用 ASP.NET Core 标识(Identity)框架创建用户和角色?
ASP.NET Core 标识(Identity)框架系列(一):如何使用 ASP.NET Core 标识(Identity)框架创建用户和角色?
|
7月前
|
开发框架 前端开发 .NET
进入ASP .net mvc的世界
进入ASP .net mvc的世界
|
7月前
|
SQL 开发框架 JavaScript
分享33个ASP.NET电子商务源码和40个ASP.NET控件组件源码,总有一款适合您
分享33个ASP.NET电子商务源码和40个ASP.NET控件组件源码,总有一款适合您
96 0
|
7月前
|
存储 开发框架 .NET
Asp.Net第一章入门之后台处理程序
Asp.Net第一章入门之后台处理程序
57 0
下一篇
DataWorks