如何将javascript var传递到asp.net上的服务器端 [英] How to pass javascript var to server side on asp.net

查看:72
本文介绍了如何将javascript var传递到asp.net上的服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将textarea值传递给服务器端.虽然textarea不能是runat = server.这是我的代码:

I'm trying to pass a textarea value to the server side. The textarea cant be runat=server though. heres my code:

<script type="text/javascript">
        function replace() {
            //Replace < and > on textarea
            var obj = document.getElementById('recipient_list');
            var str = obj.value;
            str = str.replace(/</i, "(");
            str = str.replace(/>/i, ")");
            obj.value = str;
            alert("rec_lst.value: " + document.getElementById('recipient_list').value);

            //Pass value to server.
            alert("passing to server");
            document.getElementById("ctl00$ContentPlaceHolder1$txtEmails").value = str;
            alert("Passed to server");
            alert("txtEmails.value: " + document.getElementById("ctl00$ContentPlaceHolder1$txtEmails").value);
        }
    </script>

这是行不通的...有关如何解决或更好地实现此目标的任何想法?..

This isn't working though... Any ideas how to fix or better implement this??..

推荐答案

尝试一下:

var txtEmail = document.getElementById("<%=txtEmails.ClientID%>");
txtEmail.value = str;

但是,这不会将任何内容传递给服务器,只需更改文本框的值即可.

However this won't pass anything to the server, just change text box value.

要将其发送到服务器,用户必须单击提交"按钮,或者,如果您具有服务器侧按钮,则具有自动单击"这样的代码,从而执行回发:

To have it sent to the server user will have to click submit button, or if you have server side button have such code to "auto click" it thus performing post back:

document.getElementById("<%=btnSubmit.ClientID%>").click();

这篇关于如何将javascript var传递到asp.net上的服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆