0

我有一个隐藏的领域

<asp:HiddenField ID="selectedRecievedValue" ClientIDMode="Static" runat="server" />

然后我有一个带有 onfocus 事件的 TextBox

<asp:TextBox runat="server" Text='<%# Eval("value") %>' CssClass="rowSpildValue"
 onfocus='<%# Eval("data_id", "document.getElementById(\"selectedDataID\").value = 
 \"{0}\"; document.getElementById(\"selectedFieldID\").value = \"rowSpildValue\";") %>'
 OnTextChanged="SpildChanged" AutoPostBack="true" ID="rowSpildValue" />

这已经运行了一些代码,但是我将如何添加另一行代码来设置我的

HiddenField = Eval("deliveredValue")
4

3 回答 3

1

您可以添加所有您喜欢的 JavaScript 代码,只需用分号分隔行

无论如何,我会这样下去,因为调试和维护可能很奇怪(它也不是跨平台的)

我建议你使用JQuery来实现这一点

于 2013-01-11T10:29:34.587 回答
1

This will work:

<asp:TextBox runat="server" Text='<%# Eval("value") %>' CssClass="rowSpildValue"
    onfocus='<%# Eval(
        "data_id", 
        "document.getElementById(\"selectedDataID\").value = \"{0}\";" +
        "document.getElementById(\"selectedFieldID\").value = \"rowSpildValue\";") + 
                Eval(
        "deliveredValue",
        "document.getElementById(\"selectedRecievedValue\").value=\"{0}\"") %>'
    OnTextChanged="SpildChanged" AutoPostBack="true" ID="rowSpildValue" />
于 2013-01-11T10:49:15.273 回答
1

将您的 JavaScript 提取为 JS 函数

<script>
   function onFocus(data_id) {
     document.getElementById("selectedDataID").value = data_id;          
     document.getElementById("selectedFieldID").value = "rowSpildValue"; 
     document.getElementById("selectedRecievedValue").value = <%# Eval("deliveredValue") %>;
   }
</script>

然后将其设置为事件处理程序

<asp:TextBox runat="server" Text='<%# Eval("value") %>' CssClass="rowSpildValue"
 onfocus='<%# Eval("data_id", "onFocus(\"{0}\");") .../>
于 2013-01-11T10:31:09.430 回答