javascript popup window not being shown

G

Guest

Hi friends,
I was writing an application to test how I could access web server control
in the client side javascript. I am trying to create a popup which would
contain the value of the button control. The code i wrote is as follows.

the aspx file
<code>
<%@ Page language="c#" Codebehind="StepByStep2_3.aspx.cs"
AutoEventWireup="false" Inherits="_315C02.StepByStep2_3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>StepByStep2_3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function btnSubscribe_ClientClick()
{
alert(document.StepByStep2_3.btnSubscribe.value + " You Suceeded");
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="StepByStep2_3" method="post" runat="server">
<asp:Button id="btnSubscribe" style="Z-INDEX: 101; LEFT: 64px; POSITION:
absolute; TOP: 40px"
runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
</code>

the .aspx.cs file
<code>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace _315C02
{
/// <summary>
/// Summary description for StepByStep2_3.
/// </summary>
public class StepByStep2_3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnSubscribe;

private void Page_Load(object sender, System.EventArgs e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSubscribe.Click += new
System.EventHandler(this.btnSubscribe_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnSubscribe_Click(object sender, System.EventArgs e)
{
btnSubscribe.Attributes.Add("OnClick","btnSubscribe_ClientClick();");
}
}
}
</code>

What do u think went wrong?
thanks
 
B

Bruce Barker

your code behind only renders the client onclick handler when the button is
clicked. so you need to click the button, wait for re-render, then click
again.

-- bruce (sqlwork.com)
 
G

Guest

Hi bruce,
Thanks for going thru such a huge code. And I do understand what u say. I
tried waiting for some time and clicking it again. But it didnt work. I
thought may be because it would try to execute both the client side code and
the server side btnSubscribe_Click() function. Then i inlcuded the line
alert(document.StepByStep2_3.btnSubscribe.value + " You Suceeded");
in the Page_Load(). And removed the btnSubscribe_Click() function. Even then
the pop up doesnt show up.
What do u think is the problem?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top