<input type="text" onclick="createCode()" readonly="readonly" id="checkCode" class="code" style="width: 100px">
时间: 2024-01-14 10:21:49 浏览: 37
根据提供的引用内容,有三种解决方法可以解决在后台无法获取设置了ReadOnly=true的TextBox控件的值的问题。
方法一:使用HiddenField控件
在前台页面中,将TextBox的值赋给一个HiddenField控件的Value属性。然后在后台代码中,通过读取HiddenField的Value属性来获取TextBox的值。
方法二:使用ViewState
在前台页面中,将TextBox的值赋给ViewState变量。然后在后台代码中,通过读取ViewState变量来获取TextBox的值。
方法三:使用Request.Form
在后台代码中,通过Request.Form来获取TextBox的值。例如,如果TextBox的id为checkCode,可以使用Request.Form["checkCode"]来获取其值。
以下是三种解决方法的示例代码:
方法一:使用HiddenField控件
```html
<input type="text" onclick="createCode()" readonly="readonly" id="checkCode" class="code" style="width: 100px">
<asp:HiddenField ID="hiddenField1" runat="server" />
<script>
function createCode() {
// 获取TextBox的值
var textBoxValue = document.getElementById("checkCode").value;
// 将TextBox的值赋给HiddenField
document.getElementById("<%= hiddenField1.ClientID %>").value = textBoxValue;
}
</script>
```
方法二:使用ViewState
```html
<input type="text" onclick="createCode()" readonly="readonly" id="checkCode" class="code" style="width: 100px">
<script>
function createCode() {
// 获取TextBox的值
var textBoxValue = document.getElementById("checkCode").value;
// 将TextBox的值赋给ViewState
<%= ViewState["textBoxValue"] = textBoxValue %>
}
</script>
```
方法三:使用Request.Form
```csharp
protected void Page_Load(object sender, EventArgs e)
{
// 获取TextBox的值
string textBoxValue = Request.Form["checkCode"];
// 使用TextBox的值
// ...
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<title>医院住院管理系统</title> </head> <body> 药品发放 <form id="drugs_delivery"> <label>*住院号:</label> <input results="s" type="search" readonly name="patientId" id="patientId" /> <label>*姓名:</label> <input type="text" readonly name="patientName" id="patientName" /> <label>*药品编号:</label> <input type="search" results="s" readonly name="drugId" id="drugsId" /> <label>数量:</label> <input type="text" name="drugCount" id="num" onblur="checkdrugsnum()" /> <input type="hidden" name="num1" id="num1"> <label>*药品名称:</label> <p cla
帮我解释这段代码 条码打印 物料编码 <label class="input"> <input type="text" class="input-xs easyui-validatebox" id="txtItemCode"> <input type="hidden" id="hdnItemId" /> </label> 物料名称 <label id="lblItemName"> </label> 物料描述 <label id="lblDescription"></label> 客户 <input type="hidden" id="hdnCustomerId" /> <label id="lblCustomer"></label> 供应商名称 <label class="input" style="width: 95%"> <input type="text" class="input-xs" style="width: 99%" id="txtVendorName" readonly="readonly"> </label>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
帮我解释这段代码 条码打印 物料编码 <label class="input"> <input type="text" class="input-xs easyui-validatebox" id="txtItemCode"> <input type="hidden" id="hdnItemId" /> </label> 物料名称 <label id="lblItemName"> </label> 物料描述 <label id="lblDescription"></label> 客户 <input type="hidden" id="hdnCustomerId" /> <label id="lblCustomer"></label> 供应商名称 <label class="input" style="width: 95%"> <input type="text" class="input-xs" style="width: 99%" id="txtVendorName" readonly="readonly"> </label>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)