简体   繁体   中英

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

<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 ;

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

Extract your JavaScript to a JS function

<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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM