Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2003, 03:57 AM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default page stuck.... what's wrong?

I typed data and clicked the submit bottom. Then, the page was stucked. It seems like repeat "PageLoad". What did I wrong?

Thanks,

 
Old December 13th, 2003, 05:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not much info! PageLoad? You mean Page_Load, right!?
 
Old December 13th, 2003, 06:29 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This following codes are the part of "Project.aspx.cs". When I click the link, "Project.aspx?action=addnew", a page for inserting data comes up. Then, I insert data on the page and click bottom, it should go to the "btnSubmit_Click" method, but it does go to "Page_Load" method again, and the same page comes up again. I hope I give you enough info.

Thanks,

    private void Page_Load(object sender, System.EventArgs e)
        {
            lblUserName.Text = "Welcome <b>" +
                    Request.Cookies["email"].Value + "</b><br><br/>";
        }

private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            MyProject.Project obj = new MyProject.Project();
            string strStatus;

            strStatus = obj.AddProject(txtProjectName.Text,
                txtBTime.Text,
                txtETime.Text,
                txtDateEvent.Text,
                txtLocationName.Text,
                txtLocationAddress.Text,
                txtProjectType.Text,
                txtRegistrationPwd.Text,
                txtUserType.Text,
                Convert.ToInt32(Request.Cookies["UserID"].Value));
........

 
Old December 13th, 2003, 06:41 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is how ASP.net works. The page has to load every time it's called. Are you not familiar with the stateless paradigm of web applications?

Page_Load gets executed for every single page hit to a page. The other events are fired based on the contents of the posted web form. ASP.net figures that out and then fires the appropriate events.

Is the button click event handler not running? Is it set correctly in the "OnClick" attribute of the button control in the HTML markup?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 13th, 2003, 08:04 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The HTML part is following:
<asp:Button ID="btnSubmit" Text="Add New Project" Runat="server" />
It doesn't have a "OnClick" attribute. Maybe, it's a problem?

Thanks,

 
Old December 13th, 2003, 08:41 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That could certainly be the problem. For a control event to fire you need to have the button's event wired to the event handler. This requires either that onClick attribute or some codebehind wiring.

When you create a button and you double click on it in the VS designer, VS should wire it for you. In C# it looks like this:

private void InitializeComponent()
{
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load);
}

This code is in the "Web Form Designer generated code" region of the code-behind.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 13th, 2003, 09:03 PM
kaz kaz is offline
Authorized User
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I checked the InitializeComponent() in "Web Form Designer generated code". As you see, it doesn't do anything with the event handler.

Thanks,

private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }

 
Old December 13th, 2003, 11:53 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well then, I imagine that is the source of your problem. Try wiring the button click event to the correct handler for it and see what happens.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
about wrong page redirect! jason_lai ASP.NET 2.0 Basics 2 June 6th, 2007 08:31 PM
stuck on page 131 crackass BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 December 1st, 2005 12:40 PM
Stuck At Page 140 Yap Dreamweaver (all versions) 2 October 12th, 2004 06:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.