我正在尝试使用以下代码从后面的代码中获取文本区域值。
HtmlTextArea bodytextarea = new HtmlTextArea();
bodytextarea = (HtmlTextArea)(this.FindControl("codearea"));
string txtbod = bodytextarea.Value;
当我调试它时,我得到一个空引用异常,指出 bodytextarea 为空。我必须提到我的 textarea 不是 runat="server"并且我不想在服务器端创建它。有帮助吗?
最佳答案
您应该添加 runat="server"
给你的<TextArea id="myTextArea" runat="server" />
这样就可以直接通过textarea的ID在后面的代码中获取值
如果您不想使用服务器端,那么您必须使用 Jquery 来获取值并创建一个 [webmethod]
在你的代码后面的方法,所以 Jquery 可以调用该方法传递值
或简单地 string data = request["codearea"];
关于c# - 在代码隐藏中获取文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11609330/