ASP.Net/Ajax/ClientScript — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:30, 26 мая 2010
ClientScript.RegisterClientScriptBlock
<%@ 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">
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:Button ID="Button1"
runat="server" Text="Button" OnClientClick="Test()"/>
</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" +
"else\n" +
"{\n" +
"alert("You Entered: " + what." + this.TextBox1.ClientID + ".value);" +
"}\n" +
"}\n" +
"//--></script>\n";
ClientScript.RegisterClientScriptBlock(typeof(Page),"Test",JScript);
}
}