如何获得html文本框中的值而不给出runat ="server" [英] how to get value which is in a html text box without giving runat="server"

查看:50
本文介绍了如何获得html文本框中的值而不给出runat ="server"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<table>
<tr>
<td>
<input type="text" id="txt" name="txt" />
</td>
</tr>
</table>






我正在html文本框中输入一些文本.
在不使用runat ="server"的情况下,如何使用C#将其插入表中?

如果我给出runat ="server",我必须给出
这样的C#




Hi,

I am typing some text in html text box.
Without giving runat ="server" how can I insert this into table using C#?

If I give runat ="server" I have to give in C# like

session["user"] = txt.value;



我想知道如何在不使用runat="server"



I want to know how to do it without using runat="server"

推荐答案

的情况下执行此操作,为什么不想使用runat ="server" ??

无论如何,这是解决方案:-

您可以使用

Why you don''t want to use runat="server"??

anyways here is the solution :-

You can use

var txtvalue = document.getElementById("txt").value;



但是您仍然必须将此值(txtvalue)保存到任何隐藏的字段中,以便在后面的代码中进一步使用.

赞:-



but still you have to save this value (txtvalue) into any hidden field for further use in code behind.

Like:-

var txtvalue = document.getElementById("txt").value;

document.getElementById("<%=HiddenField1.ClientID %>").value = txtvalue;


现在,您可以在后面的代码中使用此隐藏字段值.

像:-


Now you can use this hidden field value in code behind.

Like :-

session["user"] = HiddenField1.value;



--------------------------
您还可以通过此方法获得价值:-



--------------------------
You can also get value by this also :-

session["user"] = Request.Form["txt"];




您可以使用Jquery或基本的xmlhttprequest进行操作.

Hi,

you can do by using Jquery or basic xmlhttprequest.


.get(" ,{用户名:
.get("Default.aspx?action=getusername",{username:


这篇关于如何获得html文本框中的值而不给出runat ="server"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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