all groups > asp.net building controls > august 2005 >
You're in the

asp.net building controls

group:

processing postback


Re: processing postback stcheng NO[at]SPAM online.microsoft.com
8/2/2005 12:00:00 AM
asp.net building controls:
Hi TS,

Welcome to ASPNET newsgroup.
Regarding on the post back event handling problem in composite control,
generaly speaking , the most likely cause is still the event handler's
registering sequence and the control's constructing and adding approach.

For your former problem, (postback event for sub controls not fire when the
composite control doesn't implement INamingContainer), this is because for
sub controls contained in composite control, they need to be assigned an
unique clientID which will be used when it's postback event be fired( the
runtime will use this ID to mapping the event to the correct control
instance). When we didn't implement NamingContainer interface, the
composite control won't assign the appropriate ClientID(also UniqueID) for
the nested sub controls, so sub controls' post back event won't be handled
correclty.

As for the new problem you mentioned, I'm wondering how did you create your
composite control (also its nested sub composite controls inside it)? For
the "Page" property, it'll be assigned properly when a certain control is
added into its container control's Controls collection, we don't need to
manually assign it. Anyway, would you try provide some code snippet to
represent your composite control's code logic? It'll be much helpful if you
can make a very simple repro demo control to demostrate the problem.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)






--------------------
| From: "TS" <manofsteele1@nospam.nospam>
| References: <#McrIf4lFHA.3380@TK2MSFTNGP10.phx.gbl>
<OvLXmC5lFHA.2904@tk2msftngp13.phx.gbl>
<eqErbF5lFHA.2916@TK2MSFTNGP14.phx.gbl>
<ueXTvQ5lFHA.2852@TK2MSFTNGP15.phx.gbl>
<ODm5H15lFHA.3256@TK2MSFTNGP12.phx.gbl>
| Subject: Re: processing postback
| Date: Tue, 2 Aug 2005 15:54:05 -0500
| Lines: 717
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <ea4lTR6lFHA.1464@TK2MSFTNGP14.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.buildingcontrols,microsoft.public.d
otnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10237
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3976
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| I have a new issue:
|
| One of my controls in my composite control is in itself a composite
control.
| It has an event that is raised when one of its drop down lists selected
| index changes. In main composite control, i hook into this other control's
| event so that i can do processing. This event won't fire in either the
drop
| down list's selected index change event handler and also not in the event
| handler that my main control subscribes to.
|
| I have a clue that may be the reason: In this sub composite control, it
| tries to access the page property, which is null when it's
| CreateChildControls. So how i fixed it was to assign this composite
| control's page property to my main control's page property so that it now
| can access the page property. I'm wondering if this has something to do
with
| the event not firing.
|
| thanks
|
[quoted text, click to view]
| > I figured it out, i wasnt' implementing INamingContainer. that fixes
| > it...BUT WHY DOES THIS IMPACT IF EVENTS GET FIRED OR NOT????
| >
| >
[quoted text, click to view]
| > > I think i maybe should be doing this at all because i can just access
| the
| > > control's value because that control handles the functionality
| > automatically
| > > that I was trying to do.
| > >
| > > If this is so, then i still have a problem: How do i raise events in
my
| > > control for controls i have created in createchildcontrols? I have the
| > > controls wired up to event handlers, but they are never hit.
| > >
| > > What do i need to do?
| > >
| > > thanks
| > >
[quoted text, click to view]
| > > > i followed the article at:
| > > >
| > >
| >
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconpostbackdataprocessingsample.asp
| > > > and it works like that except like i said when I use
| createchildControls
| > > > instead of render (because i need to render multiple controls), it
| > doesn't
| > > > hit those postback methods.
| > > >
| > > > thanks again
| > > >
[quoted text, click to view]
| > > > > Well i know it has something to do with the CREATEChildControls
| method
| > > > > because when i overrode render instead of doing that method at
all,
| > the
| > > > > LoadPostData() was executed. I guess it has something to do with
the
| > > > > controls being recreated each time, I DON"T KNOW.
| > > > >
| > > > > I need help all of you master coders :-)
| > > > >
| > > > >
[quoted text, click to view]
| > > > > > i have a composite control that has dropdowns on them. The page
| will
| > > > post
| > > > > > back on change, but their events won't raise. Can anyone tell me
| > whats
| > > > > going
| > > > > > on? I tried to use the IPostBackDataHandler to try to get a hold
| of
| > > the
| > > > > > control to set values and such, but it has been no help. I'm
| > confused
| > > at
| > > > > how
| > > > > > this control is supposed to work. I want it to be self contained
| so
| > > that
| > > > > > when a control changes, it posts back and then reloads its
| dependent
| > > > drop
| > > > > > down lists with data that is filtered based on the value of the
| > > control
| > > > > that
| > > > > > changed.
| > > > > >
| > > > > > Every time the page posts back to server, the it hits the init
and
| > > load
| > > > > > events and createchildcontrols, but thats it. i can't get into
the
| > > > > > XXX_SelectedIndexChanged events for some reason even though they
| are
| > > > wired
| > > > > > to do so.
| > > > > >
| > > > > > Any help will be appreaciated as i'm starting to feel dumb.
| > > > > >
| > > > > > using System;
| > > > > >
| > > > > > using System.Collections.Specialized;
| > > > > >
| > > > > > using System.Web.UI;
| > > > > >
| > > > > > using System.Web.UI.WebControls;
| > > > > >
processing postback TS
8/2/2005 12:29:47 PM
i have a composite control that has dropdowns on them. The page will post
back on change, but their events won't raise. Can anyone tell me whats going
on? I tried to use the IPostBackDataHandler to try to get a hold of the
control to set values and such, but it has been no help. I'm confused at how
this control is supposed to work. I want it to be self contained so that
when a control changes, it posts back and then reloads its dependent drop
down lists with data that is filtered based on the value of the control that
changed.

Every time the page posts back to server, the it hits the init and load
events and createchildcontrols, but thats it. i can't get into the
XXX_SelectedIndexChanged events for some reason even though they are wired
to do so.

Any help will be appreaciated as i'm starting to feel dumb.

using System;

using System.Collections.Specialized;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using Operations.Teams.Business;

using Operations.Teams.Data;

using Operations.Teams.Reporting;

using Operations.Teams.Reporting.WebControls;

namespace Operations.Teams.Web.ReportControls

{

/// <summary>

/// Summary description for FiscalAgentHierarchy.

/// </summary>

public class FiscalAgentHierarchy : Control, IReportParameterControl,
IPostBackDataHandler

{

public FiscalAgentHierarchy()

{

Parameters.Add(new Parameter("@SchoolYear"));

Parameters.Add(new Parameter("@ReportingGroup"));

Parameters.Add(new Parameter("@FiscalAgentID"));

Parameters.Add(new Parameter("@FundingSourceID"));

Parameters.Add(new Parameter("@ProviderID"));

Parameters.Add(new Parameter("@SiteID"));

Parameters.Add(new Parameter("@ClassID"));

Parameters["@SchoolYear"].Value = 2006;

}


#region Events


public bool LoadPostData(string postDataKey, NameValueCollection postData)

{

string postedValue = postData[postDataKey];

return true;

}

public void RaisePostDataChangedEvent()

{

rysReportingYearSelector_ReportingYearChanged(this, EventArgs.Empty);

}

protected override void LoadViewState(object savedState)

{

string zasdf="asdlfkjds";

}

protected override object SaveViewState()

{

string zsad="asdf";

}

protected override void OnInit(EventArgs e)

{

//this.EnsureChildControls();


// Do whatever the control usually does OnInit

base.OnInit(e);

}

protected override void OnLoad(EventArgs e)

{

//this.EnsureChildControls();

// Do whatever the control usually does OnInit

base.OnLoad(e);

}

private void rysReportingYearSelector_ReportingYearChanged(object sender,
EventArgs e)

{

this.LoadFundingSource();

this.LoadProviders();

}

private void fasFiscalAgent_FiscalAgentChanged(object sender, EventArgs e)

{

this.LoadFundingSource();

this.LoadProviders();

}

private void ddlProviders_SelectedIndexChanged(object sender, EventArgs e)

{

LoadSites();

}

private void ddlSites_SelectedIndexChanged(object sender, EventArgs e)

{

LoadClasses();

}

#endregion

protected override void CreateChildControls()

{

rysReportingYearSelector = new ReportingYearReportSelector();

fasFiscalAgent = new FiscalAgentReportSelector();

this.ddlFundingSource = new DropDownList();

this.ddlProviders = new DropDownList();

this.ddlSites = new DropDownList();

this.ddlClasses = new DropDownList();

rysReportingYearSelector.ID = ReportingYearSelectorControlId;

fasFiscalAgent.ID = FiscalAgentSelectorControlId;

ddlFundingSource.ID = FundingSourceControlId;

ddlProviders.ID = ProvidersControlId;

ddlSites.ID = SitesControlId;

ddlClasses.ID = ClassesControlId;

// Assign these controls' Page property because when they try to access Page
they get null reference - apparently they aren't in the control tree at that
point

rysReportingYearSelector.Page = this.Page;

fasFiscalAgent.Page = this.Page;

rysReportingYearSelector.ReportingYearChanged += new
EventHandler(rysReportingYearSelector_ReportingYearChanged);

fasFiscalAgent.FiscalAgentChanged += new
EventHandler(fasFiscalAgent_FiscalAgentChanged);

ddlProviders.SelectedIndexChanged += new
EventHandler(ddlProviders_SelectedIndexChanged);

ddlSites.SelectedIndexChanged += new
EventHandler(ddlSites_SelectedIndexChanged);

fasFiscalAgent.IsSubmitOnChange = true;

ddlProviders.AutoPostBack = true;

ddlSites.AutoPostBack = true;

// this.SchoolYear = rysReportingYearSelector.SchoolYear;

// check if can populate funding sources and providers (because fiscalAgent
has been saved in session)

if(this.fasFiscalAgent.SelectedFiscalAgentName != string.Empty)

{

LoadFundingSource();

LoadProviders();

}

else

{

ddlFundingSource.Visible = false;

ddlProviders.Visible = false;

}

// Initially set to false until their direct parent's selection has been
made (all other controls will have data on page load)

ddlSites.Visible = false;

ddlClasses.Visible = false;

// start containing table

this.Controls.Add(WebHelper.MakeLiteral("<table cellpadding=0
cellspacing=0><tr><td>"));


this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));

this.Controls.Add(rysReportingYearSelector);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));

this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>"));

this.Controls.Add(fasFiscalAgent);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));

this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Funding
Source</td><td>"));

this.Controls.Add(ddlFundingSource);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));

this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Providers</td><td>")
);

this.Controls.Add(ddlProviders);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));

this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Sites</td><td>"));

this.Controls.Add(ddlSites);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

this.Controls.Add(WebHelper.MakeLiteral("</td></tr><tr><td>"));

this.Controls.Add(WebHelper.MakeLiteral("<table><tr><td>Classes</td><td>"));

this.Controls.Add(ddlClasses);

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

// end containing table

this.Controls.Add(WebHelper.MakeLiteral("</td></tr></table>"));

}

private void LoadFundingSource()

{

int fiscalAgentId = this.fasFiscalAgent.SelectedFiscalAgentId;


if(fiscalAgentId != int.MinValue)

{

this.ddlFundingSource.Visible = true;

this.ddlFundingSource.DataSource = FiscalAgentFunding.Find(fiscalAgentId);

Re: processing postback TS
8/2/2005 1:33:14 PM
Well i know it has something to do with the CREATEChildControls method
because when i overrode render instead of doing that method at all, the
LoadPostData() was executed. I guess it has something to do with the
controls being recreated each time, I DON"T KNOW.

I need help all of you master coders :-)


[quoted text, click to view]
Re: processing postback TS
8/2/2005 1:38:18 PM
i followed the article at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconpostbackdataprocessingsample.asp
and it works like that except like i said when I use createchildControls
instead of render (because i need to render multiple controls), it doesn't
hit those postback methods.

thanks again

[quoted text, click to view]
Re: processing postback TS
8/2/2005 1:58:32 PM
I think i maybe should be doing this at all because i can just access the
control's value because that control handles the functionality automatically
that I was trying to do.

If this is so, then i still have a problem: How do i raise events in my
control for controls i have created in createchildcontrols? I have the
controls wired up to event handlers, but they are never hit.

What do i need to do?

thanks

[quoted text, click to view]
Re: processing postback TS
8/2/2005 3:03:39 PM
I figured it out, i wasnt' implementing INamingContainer. that fixes
it...BUT WHY DOES THIS IMPACT IF EVENTS GET FIRED OR NOT????


[quoted text, click to view]
Re: processing postback TS
8/2/2005 3:54:05 PM
I have a new issue:

One of my controls in my composite control is in itself a composite control.
It has an event that is raised when one of its drop down lists selected
index changes. In main composite control, i hook into this other control's
event so that i can do processing. This event won't fire in either the drop
down list's selected index change event handler and also not in the event
handler that my main control subscribes to.

I have a clue that may be the reason: In this sub composite control, it
tries to access the page property, which is null when it's
CreateChildControls. So how i fixed it was to assign this composite
control's page property to my main control's page property so that it now
can access the page property. I'm wondering if this has something to do with
the event not firing.

thanks

[quoted text, click to view]
Re: processing postback intrader
8/3/2005 12:00:00 AM
[quoted text, click to view]
Re: processing postback TS
8/5/2005 8:34:54 AM
thanks, but it seems my only problem that still exists is the posts i'm
making in "explanation of when need..."


[quoted text, click to view]
Re: processing postback stcheng NO[at]SPAM online.microsoft.com
8/7/2005 12:00:00 AM
OK. I'll continue to followup in your "explanation of when need..." issue.
Please feel free to post there.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "TS" <manofsteele1@nospam.nospam>
| References: <#McrIf4lFHA.3380@TK2MSFTNGP10.phx.gbl>
<OvLXmC5lFHA.2904@tk2msftngp13.phx.gbl>
<eqErbF5lFHA.2916@TK2MSFTNGP14.phx.gbl>
<ueXTvQ5lFHA.2852@TK2MSFTNGP15.phx.gbl>
<ODm5H15lFHA.3256@TK2MSFTNGP12.phx.gbl>
<ea4lTR6lFHA.1464@TK2MSFTNGP14.phx.gbl>
<0xRSN28lFHA.940@TK2MSFTNGXA01.phx.gbl>
| Subject: Re: processing postback
| Date: Fri, 5 Aug 2005 08:34:54 -0500
| Lines: 848
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <O3JE4JcmFHA.3256@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:4000
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| thanks, but it seems my only problem that still exists is the posts i'm
| making in "explanation of when need..."
|
|
[quoted text, click to view]
| > Hi TS,
| >
| > Welcome to ASPNET newsgroup.
| > Regarding on the post back event handling problem in composite control,
| > generaly speaking , the most likely cause is still the event handler's
| > registering sequence and the control's constructing and adding approach.
| >
| > For your former problem, (postback event for sub controls not fire when
| the
| > composite control doesn't implement INamingContainer), this is because
for
| > sub controls contained in composite control, they need to be assigned an
| > unique clientID which will be used when it's postback event be fired(
the
| > runtime will use this ID to mapping the event to the correct control
| > instance). When we didn't implement NamingContainer interface, the
| > composite control won't assign the appropriate ClientID(also UniqueID)
for
| > the nested sub controls, so sub controls' post back event won't be
handled
| > correclty.
| >
| > As for the new problem you mentioned, I'm wondering how did you create
| your
| > composite control (also its nested sub composite controls inside it)?
For
| > the "Page" property, it'll be assigned properly when a certain control
is
| > added into its container control's Controls collection, we don't need to
| > manually assign it. Anyway, would you try provide some code snippet to
| > represent your composite control's code logic? It'll be much helpful if
| you
| > can make a very simple repro demo control to demostrate the problem.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| >
| > --------------------
| > | From: "TS" <manofsteele1@nospam.nospam>
| > | References: <#McrIf4lFHA.3380@TK2MSFTNGP10.phx.gbl>
| > <OvLXmC5lFHA.2904@tk2msftngp13.phx.gbl>
| > <eqErbF5lFHA.2916@TK2MSFTNGP14.phx.gbl>
| > <ueXTvQ5lFHA.2852@TK2MSFTNGP15.phx.gbl>
| > <ODm5H15lFHA.3256@TK2MSFTNGP12.phx.gbl>
| > | Subject: Re: processing postback
| > | Date: Tue, 2 Aug 2005 15:54:05 -0500
| > | Lines: 717
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <ea4lTR6lFHA.1464@TK2MSFTNGP14.phx.gbl>
| > | Newsgroups:
| >
|
microsoft.public.dotnet.framework.aspnet.buildingcontrols,microsoft.public.d
| > otnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:10237
| > microsoft.public.dotnet.framework.aspnet.buildingcontrols:3976
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| > |
| > | I have a new issue:
| > |
| > | One of my controls in my composite control is in itself a composite
| > control.
| > | It has an event that is raised when one of its drop down lists
selected
| > | index changes. In main composite control, i hook into this other
| control's
| > | event so that i can do processing. This event won't fire in either the
| > drop
| > | down list's selected index change event handler and also not in the
| event
| > | handler that my main control subscribes to.
| > |
| > | I have a clue that may be the reason: In this sub composite control,
it
| > | tries to access the page property, which is null when it's
| > | CreateChildControls. So how i fixed it was to assign this composite
| > | control's page property to my main control's page property so that it
| now
| > | can access the page property. I'm wondering if this has something to
do
| > with
| > | the event not firing.
| > |
| > | thanks
| > |
[quoted text, click to view]
| > | > I figured it out, i wasnt' implementing INamingContainer. that fixes
| > | > it...BUT WHY DOES THIS IMPACT IF EVENTS GET FIRED OR NOT????
| > | >
| > | >
[quoted text, click to view]
| > | > > I think i maybe should be doing this at all because i can just
| access
| > | the
| > | > > control's value because that control handles the functionality
| > | > automatically
| > | > > that I was trying to do.
| > | > >
| > | > > If this is so, then i still have a problem: How do i raise events
in
| > my
| > | > > control for controls i have created in createchildcontrols? I have
| the
| > | > > controls wired up to event handlers, but they are never hit.
| > | > >
| > | > > What do i need to do?
| > | > >
| > | > > thanks
| > | > >
[quoted text, click to view]
| > | > > > i followed the article at:
| > | > > >
| > | > >
| > | >
| > |
| >
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
| > l/cpconpostbackdataprocessingsample.asp
| > | > > > and it works like that except like i said when I use
| > | createchildControls
| > | > > > instead of render (because i need to render multiple controls),
it
| > | > doesn't
AddThis Social Bookmark Button