fletchsod
Programmer
- Dec 16, 2002
- 181
I don't understand why the lblJavaScript1 does not work when the script is complete. When I ran the debugger, it showed the new data is updated in the lblJavaScript1 but when it is complete and a web browser appear, the view-source show there is no data in the lblJavaScript1.
Can anyone point out why it is broken? How do you make it work?
Thanks...
Can anyone point out why it is broken? How do you make it work?
Code:
//Web.Config
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
</pages>
Code:
//ASPX file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ContactUs1.aspx.cs" Inherits="contactus" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
<title></title>
</head>
<body id="contact-page">
<form id="form1" runat="server">
<div>
<!-- ASP.NET AJAX Script Only... -->
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:textbox id="txtName"
runat="server" Width="176px"></asp:textbox>
<br /><br />
<asp:Button ID="btnSubmit" runat="server"
onClick="btnSubmit_Click"
Text="Submit" Width="72px" />
<br /><br />
<asp:Label ID="lblJavaScript1" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Code:
//ASPX Code Behind
//Code Behind (ASPX.cs webpage)...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class contactus : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
string sName = this.txtName.Text.ToString().Trim();
if (sName.Length == 0)
{
this.lblJavaScriptValidation1.Text = "<script type='text/javascript'>alert('Test');</script>";
this.txtName.BackColor = System.Drawing.Color.LemonChiffon;
return; //This exit the function...
}
}
protected void Page_Load(object sender, EventArgs e)
{
this.lblJavaScriptValidation1.Text = ""; //Clear the validation error msg...
//Put user code to initialize the page here
if (!(Page.IsPostBack))
{
this.txtName.Text = "";
}
}
}
Thanks...