Link to home
Start Free TrialLog in
Avatar of sangeetaandkarthik
sangeetaandkarthik

asked on

asp.net 1.1 event handlers

Hi

How to debug asp.net 1.1 application. I worked on asp.net 2.0 and later but not with asp.net 1.1 in VS 2003. I just placed button and textbox on ui and in button click handler, i am assigning random text. But when i select the button, i am seeing blank page. why so?  what is different in running asp.net 1.1 and 2.0

below is code.

-------------------------------
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>WebForm1</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">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 120px"
                        runat="server"></asp:TextBox>
                  <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 216px" runat="server"
                        Text="Button"></asp:Button>
            </form>
      </body>
</HTML>

--------------------------
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 WebApplication2
{
      /// <summary>
      /// Summary description for WebForm1.
      /// </summary>
      public class WebForm1 : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.TextBox TextBox1;
            protected System.Web.UI.WebControls.Button Button1;
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
            }

            #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.Button1.Click += new System.EventHandler(this.Button1_Click);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void Button1_Click(object sender, System.EventArgs e)
            {
                  TextBox1.Text="foo";
            }
      }
}


Thank You,
Naresh
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Button click event causes postback. At that time the page load event is called. In page load event the text is not being set. Hence you are not able to see the value. Use the code to set the value correctly.

You can use some other options as well such as setting value in client side using Javascript and EnableViewState=true to the textbox control.

private void Page_Load(object sender, System.EventArgs e)
   {
       if(Page.IsPostBack)
       {
           TextBox1.Text="foo";
       }

    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kovilpattiBalu
kovilpattiBalu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in addition to the above, I was also expecting, an on_click in your asp tag:

chage this :
       <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 216px" runat="server"
                        Text="Button"></asp:Button>

to this:

       <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 216px" runat="server"
                        Text="Button" OnClick="Button1_Click" ></asp:Button>


to reference this in your code behind:
        private void Button1_Click(object sender, System.EventArgs e)
            {
                  TextBox1.Text="foo";
            }