简体   繁体   English

如何在ASP.NET事件中做几件事

[英]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.

相关问题 如何在onBlur事件上进行ASP.Net GridView回发? - How do I make an ASP.Net GridView postback on an onBlur event? 如何排除与ASP.Net中HttpHandler的指定路径匹配的内容? - How do I exclude things that match the specified path for an HttpHandler in ASP.Net? ASP.NET MVC和具有多个属性的多个复选框,该怎么做? - ASP.NET MVC and multiple checkboxes for several properties, how to do that? 如何创建一个在ASP.NET和非ASP.NET应用程序中工作的类库? - How do I make a class library that works in ASP.NET and non-ASP.NET applications? 如何在ASP.net中做到这一点? - How do I do this in ASP.net? 我应该创建多个ASP.Net ASCX控件还是创建多个控件的单个控件? - Should I create multiple ASP.Net ASCX Controls or a single Control to do multiple things 如何在 textbox.text_changed (ASP.NET) 上制作事件 - How to make event on textbox.text_changed (ASP.NET) 如何为将由PageHandlerFactory处理的ASP.NET中的每个请求添加事件处理程序 - How do I add an event handler for every request in ASP.NET that will be handled by PageHandlerFactory 如何停止在ASP.NET MVC中发布按钮事件? - How do I stop a button event from posting in ASP.NET MVC? 如何给 ASP.Net 自定义控件一个新的自定义事件 - How do I give an ASP.Net custom control a new custom event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM