asp.net - 我想使用 Javascript 将项目添加到 ASP.Net 组合框

标签 asp.net javascript

我想使用 Javascript 将项目添加到 ASP.Net 组合框。我可以检索 ID(无主页)。如何从 Javascript 向组合框添加值?我现在的代码如下所示。

    //Fill the years (counting 100 from the first)
    function fillvarYear() {
        var dt = $('#txtBDate').val();
        dt = dt.toString().substring(6);

        var ye = parseInt(dt);

        //Loop and add the next 100 years from the birth year to the combo
        for (var j = 1; j <= 100; j++) {
            ye += 1; //Add one year to the year count

            var opt = document.createElement("OPTION");
            opt.text = ye;
            opt.value = ye;
            document.form1.ddlYear.add(opt);
        }
    }

最佳答案

查看回传值:

string selectedValue = Request.Params[combobox.UniqueId]

请记住,使用 javascript 更改组合框中的值将导致抛出事件验证异常,这通常是一个坏主意,因为您必须明确禁用事件验证。

我建议将组合框放在更新面板中,这样您就可以在服务器上读取 txtBirthDate 并生成适当的数据。然后您也不必手动保留状态。

关于asp.net - 我想使用 Javascript 将项目添加到 ASP.Net 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/280229/

相关文章:

asp.net - NHibernate - ManagedWebSessionContext 和 WebSessionContext 有什么区别?

php - 形式变量传递

javascript - Highcharts - 如何在重叠内容时强制 dataLabels 显示标签

javascript - Ajax.Request 不适用于 IE8/9 中的 CORS,静默失败

javascript - 如何在每秒点击一次时反转动画?

asp.net - 无法为 .net 安装 "LemmatizerPrebuiltCompact"库 - Visual Studio 错误

c# - MONO 客户端和 ASP.NET 服务器之间的序列化/反序列化 - 可能吗?

asp.net - 在 ASP.NET MVC 4 中,子文件夹中的 _viewStart 文件是附加的还是单独的?

javascript - 检测所有传入的 HTTP 文件 Google Chrome 扩展

c# - 在 asp .net core 3 中使用进程内托管设置请求超时