Retrieve PostBack value of dynamic control

Discussion in 'ASP .Net Web Controls' started by Nick, May 27, 2004.

  1. Nick

    Nick Guest

    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
     
    Nick, May 27, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
     
    Robert Koritnik, May 28, 2004
    #2
    1. Advertising

  3. Nick

    Nick Guest

    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
     
    Nick, May 29, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Larry Bud
    Replies:
    1
    Views:
    356
    bruce barker
    Jan 10, 2007
  2. =?Utf-8?B?RGF2ZQ==?=

    get value of dynamic control on postback?

    =?Utf-8?B?RGF2ZQ==?=, Aug 3, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    2,047
    Eliyahu Goldin
    Aug 3, 2007
  3. Aruna Bajpayee

    retrieve value of dynamic web control

    Aruna Bajpayee, Jul 26, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    144
  4. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    483
    Eidolon
    May 4, 2004
  5. Replies:
    1
    Views:
    404
    Alessandro Zifiglio
    Apr 20, 2006
Loading...

Share This Page