![]() |
Retrieve PostBack value of dynamic control
Hi all
I am hoping that someone would respond to what I am calling a puzzle: obtain the postback value of dynamic hidden control I am posting a short version of the code, thx for your help public class AccountSummaryInfo : System.Web.UI.WebControls.WebControl, IPostBackDataHandle { #region Constructor/Deconstructo public AccountSummaryInfo(string StrAccountNum { InitializeDataGrid() BuildControls() }//End constructo #endregio private void BuildControls( { protected virtual void Click(object sender, System.EventArgs e) { Button btn = (Button)sender if (btn.CommandName.Equals("Previous") { //Code her _strKey = “Some Value” Page.Server.Transfer(cPAGENAME,true) else if (btn.CommandName.Equals("Next") //Code her _strKey = “Some Other Value” Page.Server.Transfer(cPAGENAME,true) }//End Clic private void InitializeDataGrid() }//End DefineDataGrid( private void GetData(string _strCommand { _strKey = “value A _strPreviousKey = “value 1 }//End GetData( private void CreateGrid(string[] aList { }//End CreateGrid() protected override void OnPreRender(EventArgs e) Controls.Add(new LiteralControl("<input type='hidden' name='Key' value='" + _strKey + "'>")) Controls.Add(new LiteralControl("<input type='hidden' name='PreviousKey' value='" + _strPreviousKey + "'>")) base.OnPreRender(e) }//End OnPreRender( protected override void OnInit(EventArgs e) GetData(strCommand) UpdateGrid(); base.OnInit(e) }//End OnInit( private void UpdateGrid( }//End clas }//end namespac |
Re: Retrieve PostBack value of dynamic control
First of all: CommandName & CommandArgument are posted via Command event,
not Click and because U use those it's best to fire Command event instead of Click. Second: Where do you implement IPostBackDataHandler methods? The best way is to check a sample in MSDN and create your control like it should be. If your class implements some interface it doesn't mean that all things get done automaticly. It only means that you should implement the methods and do the work by yourself. It just helps you to make correct methods. So you must implement LoadPostData and if you need to also RaisePostDataChangedEvent which executes event delegates that MAY be defined on the page that displays your Custom control. -- RobertK { Clever? No just smart. } "Nick" <anonymous@discussions.microsoft.com> wrote in message news:7C14F15A-FAED-47A8-A2F2-A00C44936271@microsoft.com... > Hi all, > I am hoping that someone would respond to what I am calling a puzzle: obtain the postback value of dynamic hidden control. > I am posting a short version of the code, thx for your help. > > public class AccountSummaryInfo : System.Web.UI.WebControls.WebControl, IPostBackDataHandler > { > #region Constructor/Deconstructor > public AccountSummaryInfo(string StrAccountNum) > { > InitializeDataGrid(); > BuildControls(); > }//End constructor > #endregion > > private void BuildControls() > { > } > protected virtual void Click(object sender, System.EventArgs e) > { > Button btn = (Button)sender; > if (btn.CommandName.Equals("Previous")) > { //Code here > _strKey = "Some Value"; > Page.Server.Transfer(cPAGENAME,true); > } > else if (btn.CommandName.Equals("Next")) > { > //Code here > _strKey = "Some Other Value"; > Page.Server.Transfer(cPAGENAME,true); > } > }//End Click > > private void InitializeDataGrid() > { > }//End DefineDataGrid() > private void GetData(string _strCommand) > { > _strKey = "value A" > _strPreviousKey = "value 1" > }//End GetData() > private void CreateGrid(string[] aList) > { > }//End CreateGrid() > > protected override void OnPreRender(EventArgs e) > { > Controls.Add(new LiteralControl("<input type='hidden' name='Key' value='" + _strKey + "'>")); > Controls.Add(new LiteralControl("<input type='hidden' name='PreviousKey' value='" + _strPreviousKey + "'>")); > base.OnPreRender(e); > }//End OnPreRender() > protected override void OnInit(EventArgs e) > { > GetData(strCommand); > UpdateGrid(); > base.OnInit(e); > }//End OnInit() > private void UpdateGrid() > { > } > }//End class > }//end namespace > |
Re: Retrieve PostBack value of dynamic control
Actually I stripped out the code for IPostBackDataHandler, but it is there
Should'nt the postback event gets fired and post the values as in Framework 1.0 Nick |
| All times are GMT. The time now is 06:30 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.