asp.net ClientScript.RegisterClientScriptBlock用法

來源:互聯網
上載者:User

asp教程.net clientscript.registerclientscriptblock用法

第一個是 registerstartups教程cript 方法。當您有一個想要在頁面載入時啟動的

網頁特效 函數時,最好使用該類

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs"

inherits="default" %>

<!doctype html public "-//w3c//dtd xhtml 1.1//en"

"http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>untitled page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:wizard id="wizard1" runat="server">
            <wizardsteps>
                <asp:wizardstep runat="server" title="step 1">
                    &nbsp;<asp:textbox id="textbox1" runat="server"

></asp:textbox>
                    <asp:button id="button1"
                        runat="server" text="button"

onclientclick="test()"/>
                    &nbsp;
                </asp:wizardstep>
                <asp:wizardstep runat="server" title="step 2">
                </asp:wizardstep>
            </wizardsteps>
        </asp:wizard>
   
    </div>
    </form>
</body>
</html>

file: default.aspx.cs

using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;

public partial class default : system.web.ui.page
{
    protected void page_load(object sender, eventargs e)
    {
    string jscript=
      "<script language=javascript> n" +
      "<!--  n" +
      "function test()n" +
      "{ n" +
      "var what = document.forms['form1']; n" +
      "if (!what) { n" +
      "what = document.form1; n" +
      "} n" +
      "if ( what." + this.textbox1.clientid + ".value=='' ) n" +
      "{ n" +
      "alert('you entered: nothing!');n" +
      "}n" +
      "elsen" +
      "{n" +
      "alert('you entered: ' + what." + this.textbox1.clientid +

".value);" +
      "}n" +
      "}n" +
      "//--></script>n";
    clientscript.registerclientscriptblock(typeof(page),"test",jscript);
    }
}

javascript 添加到位於 asp.net教程 頁面中的某個特定伺服器控制項是非常簡單的。我

們以按鈕伺服器控制項為例。如果您使用任一 microsoft visual studio 2005 將

button html 伺服器控制項(htmlinputbutton 類)拖放到某個頁面中,並將其作為

伺服器控制項運行,則應具有以下代碼結構:

<input id="button1" type="button" value="button" runat="server" />

這是一個普通按鈕,可通過 asp.net 頁面的代碼分離或伺服器端指令碼以編程方式

對其進行控制。例如,要在產生頁面時指定按鈕文本,只需在該元素變成 html 服

務器控制項(按右鍵該控制項,然後選擇 run as server control(作為伺服器控制項

運行))後使用該按鈕的 value 屬性即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.