473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

exception in page_load

Hello,

This is a button click event and it works:
private void btnSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
string myPar = txtBox.Text;
SwitchToPage(myPar);
}

I needed to switch the page if there is a parameter provided in the URL. The
following does not work on the same page although myPar is the same in both
cases, SwitchToPage return exception as "A control cannot modify its
parents' control collections"

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string myPar=Request.QueryString["MyPar"];
if(myPar!=null)
{
SwitchToPage(myPar);
}
}
}

Any idea where the problem might be? Is there any other way I can realize
the same thing?

May 10 '06 #1
5 1205
Jon
Hi,

Might be best to supply the SwitchToPage method?

Jon

"JIM.H." wrote:
Hello,

This is a button click event and it works:
private void btnSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
string myPar = txtBox.Text;
SwitchToPage(myPar);
}

I needed to switch the page if there is a parameter provided in the URL. The
following does not work on the same page although myPar is the same in both
cases, SwitchToPage return exception as "A control cannot modify its
parents' control collections"

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string myPar=Request.QueryString["MyPar"];
if(myPar!=null)
{
SwitchToPage(myPar);
}
}
}

Any idea where the problem might be? Is there any other way I can realize
the same thing?

May 10 '06 #2
Thank you very much for the reply. There are lots of things going on in
SwitchToPage’s page_load including users verification and that is not my code
I can not release it. I am just wondering although I am passing the same
string what would be the reason the system does not work.
I am also guessing the page is not loaded completely when I call
SwitchToPage method in the Page_load, is there any other layer I can call
this method. Just before page display?
"Jon" wrote:
Hi,

Might be best to supply the SwitchToPage method?

Jon

"JIM.H." wrote:
Hello,

This is a button click event and it works:
private void btnSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
string myPar = txtBox.Text;
SwitchToPage(myPar);
}

I needed to switch the page if there is a parameter provided in the URL. The
following does not work on the same page although myPar is the same in both
cases, SwitchToPage return exception as "A control cannot modify its
parents' control collections"

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string myPar=Request.QueryString["MyPar"];
if(myPar!=null)
{
SwitchToPage(myPar);
}
}
}

Any idea where the problem might be? Is there any other way I can realize
the same thing?

May 10 '06 #3
What is the exception? Are you getting a null value exception? It's probably
because you're checking for a null valuue incorrectly.

Don't try to set myPar to be the value of the querystring item without first
checking the querystring item
try this:

if(Request.QueryString["MyPar"] != null)
{
SwitchToPage(Request.QueryString["MyPar"].ToString());
}

Trying to assign a querystring item as a value to something when the
querystring item doesn't exist will throw a null exception. You have to test
the collection item first before assigning it as a value to something.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
Hello,

This is a button click event and it works:
private void btnSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
string myPar = txtBox.Text;
SwitchToPage(myPar);
}

I needed to switch the page if there is a parameter provided in the URL.
The
following does not work on the same page although myPar is the same in
both
cases, SwitchToPage return exception as "A control cannot modify its
parents' control collections"

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string myPar=Request.QueryString["MyPar"];
if(myPar!=null)
{
SwitchToPage(myPar);
}
}
}

Any idea where the problem might be? Is there any other way I can realize
the same thing?

May 10 '06 #4
Thank you very much for your reply Mark. I get the following exception. "A
control cannot modify its parents' control collections" which is fired by a
main class that is written in house which I do not have control over it.

I am sure I send a string which is not null to SwitchToPage() since I see it
on the debug mode. My guess is I should be switching this new page once
everything is loaded. Is there any way once page is loaded assumed that the
login button is clicked. When I click button it works so that would be a
solution for me.
"Mark Fitzpatrick" wrote:
What is the exception? Are you getting a null value exception? It's probably
because you're checking for a null valuue incorrectly.

Don't try to set myPar to be the value of the querystring item without first
checking the querystring item
try this:

if(Request.QueryString["MyPar"] != null)
{
SwitchToPage(Request.QueryString["MyPar"].ToString());
}

Trying to assign a querystring item as a value to something when the
querystring item doesn't exist will throw a null exception. You have to test
the collection item first before assigning it as a value to something.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
Hello,

This is a button click event and it works:
private void btnSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
string myPar = txtBox.Text;
SwitchToPage(myPar);
}

I needed to switch the page if there is a parameter provided in the URL.
The
following does not work on the same page although myPar is the same in
both
cases, SwitchToPage return exception as "A control cannot modify its
parents' control collections"

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string myPar=Request.QueryString["MyPar"];
if(myPar!=null)
{
SwitchToPage(myPar);
}
}
}

Any idea where the problem might be? Is there any other way I can realize
the same thing?


May 10 '06 #5
If you don't have control of a class written in house and it throwing an
error then speak with the class author or catch the error then deal with it.
How can you debug a black box?

SA
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
Thank you very much for your reply Mark. I get the following exception. "A
control cannot modify its parents' control collections" which is fired by
a
main class that is written in house which I do not have control over it.

I am sure I send a string which is not null to SwitchToPage() since I see
it
on the debug mode. My guess is I should be switching this new page once
everything is loaded. Is there any way once page is loaded assumed that
the
login button is clicked. When I click button it works so that would be a
solution for me.
"Mark Fitzpatrick" wrote:
What is the exception? Are you getting a null value exception? It's
probably
because you're checking for a null valuue incorrectly.

Don't try to set myPar to be the value of the querystring item without
first
checking the querystring item
try this:

if(Request.QueryString["MyPar"] != null)
{
SwitchToPage(Request.QueryString["MyPar"].ToString());
}

Trying to assign a querystring item as a value to something when the
querystring item doesn't exist will throw a null exception. You have to
test
the collection item first before assigning it as a value to something.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
> Hello,
>
> This is a button click event and it works:
> private void btnSubmit_Click(object sender,
> System.Web.UI.ImageClickEventArgs e)
> {
> string myPar = txtBox.Text;
> SwitchToPage(myPar);
> }
>
> I needed to switch the page if there is a parameter provided in the
> URL.
> The
> following does not work on the same page although myPar is the same in
> both
> cases, SwitchToPage return exception as "A control cannot modify its
> parents' control collections"
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if(!Page.IsPostBack)
> {
> string myPar=Request.QueryString["MyPar"];
> if(myPar!=null)
> {
> SwitchToPage(myPar);
> }
> }
> }
>
> Any idea where the problem might be? Is there any other way I can
> realize
> the same thing?
>


May 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
2
by: Shannon | last post by:
I am having a very stange issue happen to my web application. I am trying to develop a simple shopping cart. The code works perfectly when I run the application under http://localhost/myapp. ...
7
by: Jon Maz | last post by:
Hi All, The following code throws a "CS0020: Division by constant zero Exception". I would have expected to see a nice, friendly "caught an exception" written to the screen. Can anyone...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: stuart | last post by:
Hi, Is it possible to find out if an exception has an inner exception or not. for example if I catch an exception of type "System.Web.HttpException" it is likely (but not definate) that the...
4
by: Terry | last post by:
Hello, I am trying to get a response for an .aspx page in my current project (same virtual directory) by using WebRequest.GetResponse but I keep getting a exception with "500 Internal server...
4
by: Prince Mathew | last post by:
Hi All, I have a requirement. I am throwing an exception from the Page_Load of my user control I want to catch this in my container page. Is this possible? The Page_Load of user control is...
2
by: Brad Baker | last post by:
I'm trying to create a custom ASP.NET custom error page however I am having some problems. Here is what I have done: 1) I've created a page called default.aspx with the following code to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.