Partial Class Source Code

C

Chris Fink

I am using VS2008 Pro and having an issue with finding a partial classes
source code so I can modify an event handler that somehow got hosed up.

I have a simple web page that is loading a user control using the
Page.LoadControl method. This usercontrol has an asp:button that is not
firing when clicked, even though the button click event is clearly defined.
I am confident the problem is with the event wiring, however I cannot find
the partial class source code to check/fix this issue. My question is how do
I find and modify the user control's partial class?

If I create a new user control it works fine since the event handler has not
been hosed up like the old one. Although I have a solution, I'd like to find
the root of the problem and understand where the partial class code resides
and how to fix this directly.

Partial classes are handy, however, we still need the ability to work with
the generated code....rarely, but the need still arises.

Thanks
 
B

bruce barker

the aspcompiler compiles the aspx page straight to a dll (no source code).
event hookup is pretty simple for click events. you just specify the handler
name, and the page compile generates the hookup.

as you are dynamically loading the user control, its probably a coding error
on your part. either you are not loading the control early enough on postback
or the control name is different on postback, so the triggering control is
not found (as its name is different)

-- bruce (sqlwork.com)
 
C

Chris Fink

Hi Bruce,

Thank You for your response. I now agree that this is a coding issue,
however, I do not know the correct resolution.

Following is a code snippet.

protected void Page_Load(object sender, EventArgs e)
{
//Clear the control place holders
phStatus.Controls.Clear();

// the control's btn click event works fine from here
//LoadStatus("123");

// if querystring is present, load the form in read only mode
// another page has a querystring link that points to this page
if (Request["id"] != null)
{
LoadForm106(Request.QueryString["id"].ToString());
// But when i try to load the user control from here, the btn
does not fire
LoadStatus("123");
EnableControls(false);
}
}

protected void LoadStatus(string RequestGUID)
{
StatusApprovalControl uc =
(StatusApprovalControl)Page.LoadControl("~/controls/StatusApprovalControl.ascx");
uc.ID = "ucStatusApproval";
phStatus.Controls.Add(uc);
}

Essentially what I have here is a data entry form that contains a status
placeholder named phStatus. On initial page load, phStatus not loaded. A
user clicks on the form's submit button and is redirected to a success.aspx
page that displays a link+querystring back to the data entry form. This
querystring is then used to load the form as ready only and also dynamically
loads the StatusApprovalControl.ascx for the first time into the phStatus
placeholder. All works fine except the buttons in the StatusApprovalControl
do not fire.

If this code is insufficient to present the problem, could you please
elaborate on some additional things I should look for. I've tried to load
the control on the Page OnInit with the same results.

protected override void OnInit(EventArgs e)
{
base.OnInit(e);

//Clear the control place holders
phStatus.Controls.Clear();

if (Request["id"] != null)
{
LoadForm106(Request.QueryString["id"].ToString());
LoadStatus(Request.QueryString["id"].ToString());
EnableControls(false);
}
}

The triggering control's name is also set on Page Load but it is most likely
this is the root of my problem but I'm not sure what I need to do to fix it.

Thanks for your help
 
C

Chris Fink

Issue resolved. I had a validator on the parent page causing the control
not to postback. Once I cleared the validation the user control worked as
planned.

My instinct told me it wasn't something to do with the naming or timing of
the usercontrol load...but sometimes when applications get big you tend to
overlook the obvious.

Thanks for your help

Chris Fink said:
Hi Bruce,

Thank You for your response. I now agree that this is a coding issue,
however, I do not know the correct resolution.

Following is a code snippet.

protected void Page_Load(object sender, EventArgs e)
{
//Clear the control place holders
phStatus.Controls.Clear();

// the control's btn click event works fine from here
//LoadStatus("123");

// if querystring is present, load the form in read only mode
// another page has a querystring link that points to this page
if (Request["id"] != null)
{
LoadForm106(Request.QueryString["id"].ToString());
// But when i try to load the user control from here, the btn
does not fire
LoadStatus("123");
EnableControls(false);
}
}

protected void LoadStatus(string RequestGUID)
{
StatusApprovalControl uc =
(StatusApprovalControl)Page.LoadControl("~/controls/StatusApprovalControl.ascx");
uc.ID = "ucStatusApproval";
phStatus.Controls.Add(uc);
}

Essentially what I have here is a data entry form that contains a status
placeholder named phStatus. On initial page load, phStatus not loaded. A
user clicks on the form's submit button and is redirected to a success.aspx
page that displays a link+querystring back to the data entry form. This
querystring is then used to load the form as ready only and also dynamically
loads the StatusApprovalControl.ascx for the first time into the phStatus
placeholder. All works fine except the buttons in the StatusApprovalControl
do not fire.

If this code is insufficient to present the problem, could you please
elaborate on some additional things I should look for. I've tried to load
the control on the Page OnInit with the same results.

protected override void OnInit(EventArgs e)
{
base.OnInit(e);

//Clear the control place holders
phStatus.Controls.Clear();

if (Request["id"] != null)
{
LoadForm106(Request.QueryString["id"].ToString());
LoadStatus(Request.QueryString["id"].ToString());
EnableControls(false);
}
}

The triggering control's name is also set on Page Load but it is most likely
this is the root of my problem but I'm not sure what I need to do to fix it.

Thanks for your help

bruce barker said:
the aspcompiler compiles the aspx page straight to a dll (no source code).
event hookup is pretty simple for click events. you just specify the handler
name, and the page compile generates the hookup.

as you are dynamically loading the user control, its probably a coding error
on your part. either you are not loading the control early enough on postback
or the control name is different on postback, so the triggering control is
not found (as its name is different)

-- bruce (sqlwork.com)
 
C

Chris Fink

Hi John,

As I stated in my past post, I had a validator on the parent page causing
the control not to postback. Once I cleared the validation the user control
worked as
planned.

Hope that helps
 

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,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top