Registering onclick of a programatically created button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Q3liZXJNYW5fKE1DRFNUISk=?=

    Registering onclick of a programatically created button

    Hi,
    I programmaticall y create a/some buttons:

    private TableCell GenerateButtonI nCell(XmlNode NodeItem)
    {
    Button ChoosePlanButto n = new Button();
    ChoosePlanButto n.CommandArgume nt = NodeItem.OuterX ml;
    ChoosePlanButto n.UseSubmitBeha vior = false;
    ChoosePlanButto n.ToolTip = "Request this plan";
    ChoosePlanButto n.Text = String.Concat(" Apply");
    TableCell InnerTableCell = new TableCell();
    InnerTableCell. Controls.Add(Ch oosePlanButton) ;
    return InnerTableCell;
    }


    I attach it/them all to the same handler:

    void ChoosePlanButto n_Click(object sender, EventArgs e)
    {
    //PERSIST THE CHOSEN PLANS ATTRIBUTES TO VIEWSTATE
    Button temp = (Button)sender;
    ViewState.Add(" ChosenPlan", temp.CommandArg ument);

    }

    then I try to register them pre page render thus:

    override protected void OnInit(EventArg s e)
    {

    if (ChoosePlanButt on != null)
    { ChoosePlanButto n.Click += new
    EventHandler(Ch oosePlanButton_ Click); }

    base.OnInit(e);

    }

    but obviously I cant reference the ChoosePlanButto n instance outside the
    method.

    How do accomplish this?

    Many thanks.
  • =?Utf-8?B?TWlzYmFoIEFyZWZpbg==?=

    #2
    RE: Registering onclick of a programatically created button

    you could simply register the event/handler in your GenerateButtonI nCell
    function

    --
    Misbah Arefin



    "CyberMan_(MCDS T!)" wrote:
    Hi,
    I programmaticall y create a/some buttons:
    >
    private TableCell GenerateButtonI nCell(XmlNode NodeItem)
    {
    Button ChoosePlanButto n = new Button();
    ChoosePlanButto n.CommandArgume nt = NodeItem.OuterX ml;
    ChoosePlanButto n.UseSubmitBeha vior = false;
    ChoosePlanButto n.ToolTip = "Request this plan";
    ChoosePlanButto n.Text = String.Concat(" Apply");
    TableCell InnerTableCell = new TableCell();
    InnerTableCell. Controls.Add(Ch oosePlanButton) ;
    return InnerTableCell;
    }
    >
    >
    I attach it/them all to the same handler:
    >
    void ChoosePlanButto n_Click(object sender, EventArgs e)
    {
    //PERSIST THE CHOSEN PLANS ATTRIBUTES TO VIEWSTATE
    Button temp = (Button)sender;
    ViewState.Add(" ChosenPlan", temp.CommandArg ument);
    >
    }
    >
    then I try to register them pre page render thus:
    >
    override protected void OnInit(EventArg s e)
    {
    >
    if (ChoosePlanButt on != null)
    { ChoosePlanButto n.Click += new
    EventHandler(Ch oosePlanButton_ Click); }
    >
    base.OnInit(e);
    >
    }
    >
    but obviously I cant reference the ChoosePlanButto n instance outside the
    method.
    >
    How do accomplish this?
    >
    Many thanks.

    Comment

    • =?Utf-8?B?Q3liZXJNYW5fKE1DRFNUKV9udXVi?=

      #3
      RE: Registering onclick of a programatically created button

      I tried that, it doesnt get called...

      Perhaps I am missing something obvious???

      I will try it again.


      --
      If I can help, I will.
      Do the same for a stranger today.


      "Misbah Arefin" wrote:
      you could simply register the event/handler in your GenerateButtonI nCell
      function
      >
      --
      Misbah Arefin
      >
      >
      >
      "CyberMan_(MCDS T!)" wrote:
      >
      Hi,
      I programmaticall y create a/some buttons:

      private TableCell GenerateButtonI nCell(XmlNode NodeItem)
      {
      Button ChoosePlanButto n = new Button();
      ChoosePlanButto n.CommandArgume nt = NodeItem.OuterX ml;
      ChoosePlanButto n.UseSubmitBeha vior = false;
      ChoosePlanButto n.ToolTip = "Request this plan";
      ChoosePlanButto n.Text = String.Concat(" Apply");
      TableCell InnerTableCell = new TableCell();
      InnerTableCell. Controls.Add(Ch oosePlanButton) ;
      return InnerTableCell;
      }


      I attach it/them all to the same handler:

      void ChoosePlanButto n_Click(object sender, EventArgs e)
      {
      //PERSIST THE CHOSEN PLANS ATTRIBUTES TO VIEWSTATE
      Button temp = (Button)sender;
      ViewState.Add(" ChosenPlan", temp.CommandArg ument);

      }

      then I try to register them pre page render thus:

      override protected void OnInit(EventArg s e)
      {

      if (ChoosePlanButt on != null)
      { ChoosePlanButto n.Click += new
      EventHandler(Ch oosePlanButton_ Click); }

      base.OnInit(e);

      }

      but obviously I cant reference the ChoosePlanButto n instance outside the
      method.

      How do accomplish this?

      Many thanks.

      Comment

      Working...