{"id":237653,"date":"2022-03-26T09:01:07","date_gmt":"2022-03-26T01:01:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=237653"},"modified":"2022-03-14T10:03:20","modified_gmt":"2022-03-14T02:03:20","slug":"to-server-controls","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/to-server-controls.html","title":{"rendered":"ASP.NET Web Forms – \u670d\u52a1\u5668\u63a7\u4ef6\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u670d\u52a1\u5668\u63a7\u4ef6\u662f\u670d\u52a1\u5668\u53ef\u7406\u89e3\u7684\u6807\u7b7e\u3002HTML \u670d\u52a1\u5668\u63a7\u4ef6\u662f\u670d\u52a1\u5668\u53ef\u7406\u89e3\u7684 HTML \u6807\u7b7e\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u7ecf\u5178 ASP \u7684\u5c40\u9650\u6027<\/strong><\/div>\n

\u4e0b\u9762\u5217\u51fa\u7684\u4ee3\u7801\u662f\u4ece\u4e0a\u4e00\u7ae0\u4e2d\u590d\u5236\u7684\uff1a<\/p>\n

<html>\r\n<body bgcolor=\"yellow\">\r\n<center>\r\n<h2>Hello Runoob!<\/h2>\r\n<p><%Response.Write(now())%><\/span><\/p>\r\n<\/center>\r\n<\/body>\r\n<\/html><\/pre>\n

\u4e0a\u9762\u7684\u4ee3\u7801\u53cd\u6620\u51fa\u7ecf\u5178 ASP \u7684\u5c40\u9650\u6027\uff1a\u4ee3\u7801\u5757\u5fc5\u987b\u653e\u7f6e\u5728\u60a8\u60f3\u8981\u8f93\u51fa\u663e\u793a\u7684\u4f4d\u7f6e\u3002<\/p>\n

\u901a\u8fc7\u7ecf\u5178 ASP\uff0c\u60f3\u8981\u628a\u53ef\u6267\u884c\u4ee3\u7801\u4ece HTML \u9875\u9762\u4e2d\u5206\u79bb\u51fa\u6765\u662f\u4e0d\u53ef\u80fd\u7684\u3002\u8fd9\u8ba9\u9875\u9762\u53d8\u5f97\u96be\u4ee5\u9605\u8bfb\uff0c\u4e5f\u96be\u4ee5\u7ef4\u62a4\u3002<\/p>\n

ASP.NET - \u670d\u52a1\u5668\u63a7\u4ef6<\/strong><\/div>\n

ASP.NET \u901a\u8fc7\u670d\u52a1\u5668\u63a7\u4ef6\uff0c\u5df2\u7ecf\u89e3\u51b3\u4e86\u4e0a\u8ff0\u7684\"\u610f\u5927\u5229\u9762\u6761\u5f0f\u4ee3\u7801\"\u95ee\u9898\u3002<\/p>\n

\u670d\u52a1\u5668\u63a7\u4ef6\u662f\u670d\u52a1\u5668\u53ef\u7406\u89e3\u7684\u6807\u7b7e\u3002<\/p>\n

\u6709\u4e09\u79cd\u7c7b\u578b\u7684\u670d\u52a1\u5668\u63a7\u4ef6\uff1a<\/p>\n

    \n
  1. HTML \u670d\u52a1\u5668\u63a7\u4ef6 - \u521b\u5efa\u7684 HTML \u6807\u7b7e<\/li>\n
  2. Web \u670d\u52a1\u5668\u63a7\u4ef6 - \u65b0\u7684 ASP.NET \u6807\u7b7e<\/li>\n
  3. Validation \u670d\u52a1\u5668\u63a7\u4ef6 - \u7528\u4e8e\u8f93\u5165\u9a8c\u8bc1<\/li>\n<\/ol>\n
    ASP.NET - HTML \u670d\u52a1\u5668\u63a7\u4ef6<\/strong><\/div>\n

    HTML \u670d\u52a1\u5668\u63a7\u4ef6\u662f\u670d\u52a1\u5668\u53ef\u7406\u89e3\u7684 HTML \u6807\u7b7e\u3002<\/p>\n

    ASP.NET \u6587\u4ef6\u4e2d\u7684 HTML \u5143\u7d20\uff0c\u9ed8\u8ba4\u662f\u4f5c\u4e3a\u6587\u672c\u8fdb\u884c\u5904\u7406\u7684\u3002\u8981\u60f3\u8ba9\u8fd9\u4e9b\u5143\u7d20\u53ef\u7f16\u7a0b\uff0c\u9700\u5411 HTML \u5143\u7d20\u4e2d\u6dfb\u52a0 runat=\"server\" \u5c5e\u6027\u3002\u8fd9\u4e2a\u5c5e\u6027\u8868\u793a\uff0c\u8be5\u5143\u7d20\u5c06\u88ab\u4f5c\u4e3a\u670d\u52a1\u5668\u63a7\u4ef6\u8fdb\u884c\u5904\u7406\u3002\u540c\u65f6\u9700\u8981\u6dfb\u52a0 id \u5c5e\u6027\u6765\u6807\u8bc6\u670d\u52a1\u5668\u63a7\u4ef6\u3002id \u5f15\u7528\u53ef\u7528\u4e8e\u64cd\u4f5c\u8fd0\u884c\u65f6\u7684\u670d\u52a1\u5668\u63a7\u4ef6\u3002<\/p>\n

    \u6ce8\u91ca<\/strong>\uff1a\u6240\u6709 HTML \u670d\u52a1\u5668\u63a7\u4ef6\u5fc5\u987b\u4f4d\u4e8e\u5e26\u6709 runat=\"server\" \u5c5e\u6027\u7684 <\/p>\n

    \u6807\u7b7e\u5185\u3002runat=\"server\" \u5c5e\u6027\u8868\u660e\u4e86\u8be5\u8868\u5355\u5fc5\u987b\u5728\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u5904\u7406\u3002\u540c\u65f6\u4e5f\u8868\u660e\u4e86\u5305\u542b\u5728\u5b83\u5185\u90e8\u7684\u63a7\u4ef6\u53ef\u88ab\u670d\u52a1\u5668\u811a\u672c\u8bbf\u95ee\u3002<\/p>\n

    \u5728\u4e0b\u9762\u7684\u5b9e\u4f8b\u4e2d\uff0c\u6211\u4eec\u5728 .aspx \u6587\u4ef6\u4e2d\u58f0\u660e\u4e86\u4e00\u4e2a HtmlAnchor \u670d\u52a1\u5668\u63a7\u4ef6\u3002\u7136\u540e\u6211\u4eec\u5728\u4e00\u4e2a\u4e8b\u4ef6\u53e5\u67c4\uff08\u4e8b\u4ef6\u53e5\u67c4\u662f\u4e00\u79cd\u9488\u5bf9\u7ed9\u5b9a\u4e8b\u4ef6\u6267\u884c\u4ee3\u7801\u7684\u5b50\u4f8b\u7a0b\uff09\u4e2d\u64cd\u4f5c HtmlAnchor \u63a7\u4ef6\u7684 HRef \u5c5e\u6027\u3002Page_Load \u4e8b\u4ef6\u662f ASP.NET \u53ef\u7406\u89e3\u7684\u591a\u79cd\u4e8b\u4ef6\u4e2d\u7684\u4e00\u79cd\uff1a<\/p>\n

    <script runat=\"server\">\r\nSub Page_Load\r\nlink1.HRef=\"http:\/\/www.runoob.com\"\r\nEnd Sub\r\n<\/script>\r\n<html>\r\n<body>\r\n<form runat=\"server\">\r\n<a id=\"link1\" runat=\"server\">Visit RUNOOB!<\/a>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n

    \u53ef\u6267\u884c\u4ee3\u7801\u672c\u8eab\u5df2\u7ecf\u88ab\u79fb\u5230 HTML \u4e4b\u5916\u4e86\u3002<\/p>\n

    ASP.NET - Web \u670d\u52a1\u5668\u63a7\u4ef6<\/strong><\/div>\n

    Web \u670d\u52a1\u5668\u63a7\u4ef6\u662f\u670d\u52a1\u5668\u53ef\u7406\u89e3\u7684\u7279\u6b8a ASP.NET \u6807\u7b7e\u3002<\/p>\n

    \u5c31\u50cf HTML \u670d\u52a1\u5668\u63a7\u4ef6\uff0cWeb \u670d\u52a1\u5668\u63a7\u4ef6\u4e5f\u662f\u5728\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u7684\uff0c\u5b83\u4eec\u540c\u6837\u9700\u8981 runat=\"server\" \u5c5e\u6027\u624d\u80fd\u751f\u6548\u3002\u7136\u800c\uff0cWeb \u670d\u52a1\u5668\u63a7\u4ef6\u6ca1\u6709\u5fc5\u8981\u6620\u5c04\u4efb\u4f55\u5df2\u5b58\u5728\u7684 HTML \u5143\u7d20\uff0c\u5b83\u4eec\u53ef\u4ee5\u8868\u793a\u66f4\u590d\u6742\u7684\u5143\u7d20\u3002<\/p>\n

    \u521b\u5efa Web \u670d\u52a1\u5668\u63a7\u4ef6\u7684\u8bed\u6cd5\u662f\uff1a<\/p>\n

    <asp:control_name id=\"some_id\" runat=\"server\" \/><\/pre>\n

    \u5728\u4e0b\u9762\u7684\u5b9e\u4f8b\u4e2d\uff0c\u6211\u4eec\u5728 .aspx \u6587\u4ef6\u4e2d\u58f0\u660e\u4e86\u4e00\u4e2a Button \u670d\u52a1\u5668\u63a7\u4ef6\u3002\u7136\u540e\u6211\u4eec\u4e3a Click \u4e8b\u4ef6\u521b\u5efa\u4e00\u4e2a\u4e8b\u4ef6\u53e5\u67c4\uff0c\u7528\u6765\u6539\u53d8\u6309\u94ae\u4e0a\u7684\u6587\u672c\uff1a<\/p>\n

    <script runat=\"server\">\r\nSub submit(Source As Object, e As EventArgs)\r\nbutton1.Text=\"You clicked me!\"\r\nEnd Sub\r\n<\/script>\r\n<html>\r\n<body>\r\n<form runat=\"server\">\r\n<asp:Button id=\"button1\" Text=\"Click me!\"\r\nrunat=\"server\" OnClick=\"submit\"\/>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n
    ASP.NET - Validation \u670d\u52a1\u5668\u63a7\u4ef6<\/strong><\/div>\n

    Validation \u670d\u52a1\u5668\u63a7\u4ef6\u662f\u7528\u6765\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u3002\u5982\u679c\u7528\u6237\u8f93\u5165\u6ca1\u6709\u901a\u8fc7\u9a8c\u8bc1\uff0c\u5c06\u663e\u793a\u4e00\u6761\u9519\u8bef\u6d88\u606f\u7ed9\u7528\u6237\u3002<\/p>\n

    \u6bcf\u79cd validation \u63a7\u4ef6\u6267\u884c\u4e00\u79cd\u6307\u5b9a\u7c7b\u578b\u7684\u9a8c\u8bc1\uff08\u6bd4\u5982\u9a8c\u8bc1\u67d0\u4e2a\u6307\u5b9a\u7684\u503c\u6216\u8005\u67d0\u4e2a\u8303\u56f4\u7684\u503c\uff09\u3002<\/p>\n

    \u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5f53 Button\u3001ImageButton\u3001LinkButton \u63a7\u4ef6\u88ab\u70b9\u51fb\u65f6\uff0c\u4f1a\u6267\u884c\u9875\u9762\u9a8c\u8bc1\u3002\u60a8\u53ef\u4ee5\u8bbe\u7f6e CausesValidation \u4e3a false \uff0c\u6765\u963b\u6b62\u6309\u94ae\u63a7\u4ef6\u88ab\u70b9\u51fb\u65f6\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n

    \u521b\u5efa Validation \u670d\u52a1\u5668\u63a7\u4ef6\u7684\u8bed\u6cd5\u662f\uff1a<\/p>\n

    <asp:control_name id=\"some_id\" runat=\"server\" \/><\/pre>\n

    \u5728\u4e0b\u9762\u7684\u5b9e\u4f8b\u4e2d\uff0c\u6211\u4eec\u5728 .aspx \u6587\u4ef6\u4e2d\u58f0\u660e\u4e86\u4e00\u4e2a TextBox \u63a7\u4ef6\u3001\u4e00\u4e2a Button \u63a7\u4ef6\u3001\u4e00\u4e2a RangeValidator \u63a7\u4ef6\u3002\u5982\u679c\u9a8c\u8bc1\u5931\u8d25\uff0c\u6587\u672c \"The value must be from 1 to 100!\" \u5c06\u4f1a\u663e\u793a\u5728 RangeValidator \u63a7\u4ef6\u4e2d\uff1a<\/p>\n

    \u5b9e\u4f8b<\/strong><\/p>\n

    <html>\r\n<body>\r\n<form runat=\"server\">\r\n<p>Enter a number from 1 to 100:\r\n<asp:TextBox id=\"tbox1\" runat=\"server\" \/>\r\n<br \/><br \/>\r\n<asp:Button Text=\"Submit\" runat=\"server\" \/>\r\n<\/p>\r\n<p>\r\n<asp:RangeValidator\r\nControlToValidate=\"tbox1\"\r\nMinimumValue=\"1\"\r\nMaximumValue=\"100\"\r\nType=\"Integer\"\r\nText=\"The value must be from 1 to 100!\"\r\nrunat=\"server\" \/>\r\n<\/p>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n<\/form>\n","protected":false},"excerpt":{"rendered":"

    \u4e0b\u9762\u5217\u51fa\u7684\u4ee3\u7801\u662f\u4ece\u4e0a\u4e00\u7ae0\u4e2d\u590d\u5236\u7684\uff1a <html> <body bgcolor=”yellow […]<\/p>\n","protected":false},"author":1470,"featured_media":237648,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-237653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/237653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=237653"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/237653\/revisions"}],"predecessor-version":[{"id":245832,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/237653\/revisions\/245832"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/237648"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=237653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=237653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=237653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}