[英]How do I make several things in a ASP.NET event
I have a hidden field 我有一个隐藏的领域
<asp:HiddenField ID="selectedRecievedValue" ClientIDMode="Static" runat="server" />
I then have a TextBox with a onfocus event 然后,我有一个带有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" />
This already runs some code, but how would I add another line of code that would set my 这已经运行了一些代码,但是如何添加另一行代码来设置我的代码
HiddenField = Eval("deliveredValue")
you can add all the JavaScript code you like just separate the lines with a semicolon ; 您可以添加所有喜欢的JavaScript代码,只需用分号分隔行即可;
Anyway I would go down this way as it can be very odd to debug and maintain (it is also not cross platform) 无论如何,我都会这样下去,因为调试和维护可能很奇怪(它也不跨平台)
I would suggest you to use JQuery to achieve that 我建议您使用JQuery来实现
Extract your JavaScript to a JS function 将您的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>
and then set that as the event handler 然后将其设置为事件处理程序
<asp:TextBox runat="server" Text='<%# Eval("value") %>' CssClass="rowSpildValue"
onfocus='<%# Eval("data_id", "onFocus(\"{0}\");") .../>
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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.