在runat = server控件上运行脚本

时间:2015-09-11 06:43:16

标签: javascript asp.net runatserver

如何在具有runat = server属性的控件上运行脚本?

删除runat = server会使脚本顺利运行,但我无法访问该控件。

这是脚本。有什么想法吗?

value

感谢

2 个答案:

答案 0 :(得分:3)

您可以从后面的代码中调用该函数:

yourForm.aspx.cs:

    protected void txthSchedTimeEvent(....)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "myFunction();", true);
    }

yourForm.aspx

        <html xmlns="http://www.w3.org/1999/xhtml">
            <head id="Head1" runat="server">
                <title>My Page</title>
                <script type="text/javascript">
                    function myFunction(){
                    $("#txthSchedTime").AnyTime_picker(
                    {
                    format: "%h:%i %p", labelTitle: "Schedule Time",
                    labelHour: "Hour", labelMinute: "Minutes"
                    });
                    }
                </script>
            </head>
            <body>
                <form id="form2" runat="server">
                <table>
                    <tr> <td> 
                     <asp:TextBox ID="txthSchedTime" runat="server" 
                        style="width:100px; background-color:lightyellow">
                     </asp:TextBox>
                    </td> </tr>
                </table> 
                </form>
            </body>
        </html>

答案 1 :(得分:0)

尝试使用它,例如:

 <input runat="server" type="text" id="txthSchedTime" readonly="true" class="asclock" style="width:100px; background-color:lightyellow" onclick="setTimePicker();" />
<script>
    $("#<%=txthSchedTime.ClientID %>").val('test');

</script>

刚刚在我的本地机器上测试过它。输入获得值“test”。