This is a migrated thread and some comments may be shown as answers.

Dynamic buttons has disappeared after post back

2 Answers 298 Views
Dock
This is a migrated thread and some comments may be shown as answers.
El-Sheikh
Top achievements
Rank 1
El-Sheikh asked on 24 Feb 2009, 07:14 AM
Dear All,

Can any one help me to do the following scenario:

On page load: Read product group from database and add dynamic button for each group into Doc1(Doc1 already exist in form) - running well.

When I click any of these Doc1.product group button their event handler creates new button with event handler for each product in database related to that group and add them to Doc2. - running well.

My problem is when I click any of the Doc2.product button and after the page is post back the Doc2 return empty and the event handler does not fire.

I appreciate if any one tell me how to keep these Doc2.product buttons exist until I click different Doc1.group button then I clear the Doc2 combonents (buttons) and add new buttons with event handler related to the clicked group.

Best Regads,
MFE

2 Answers, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 24 Feb 2009, 03:32 PM
Hi El-Sheikh,

I believe that the dynamically created Button is not recreated and that is the reason for this behavior. If you add dynamically controls to RadDock you should recreate them on each postback(ajax call), otherwise they will disappear.

If you think that the problem is different, please open a new support thread and send us a running project where we could observe the problem. Once we receive it we will do our best to help you.

Sincerely yours,
Petio Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Robert
Top achievements
Rank 1
answered on 25 Feb 2009, 05:11 PM
You need to recreate your buttons on each page load. Do this in the OnInit event of you page:

protected

override void OnInit(EventArgs e)

 

{

 

    base.OnInit(e);

 

 

    BuildUI bu = new BuildUI(this.Form);

 

}


 

public

class BuildUI

 

 

 

{

 

    private HtmlForm m_HtmlForm;

 

 

    public HtmlForm HtmlForm

 

    {

 

        get { return m_HtmlForm; }

 

 

        set { m_HtmlForm = value; }

 

    }

 

    public BuildUI(HtmlForm hf)

 

    {

        m_HtmlForm = hf;

 

        Button btn = new Button();

 

 

        Panel p = (Panel)m_HtmlForm.FindControl("maincontent").FindControl("pnlBottom");

 

        p.Controls.Add(btn);

     }

}




Set the properties of your controls, somewhere in the Page_Load event of your page:





protected void Page_Load(object sender, EventArgs e)

 

{

 

     BuildUiProperties bup = new BuildUiProperties();

 

     bup.SetProperties(this.pnlBottom

);
}


public class BuildUiProperties

 

 

 

 

{

 

    Public BuildUiProperties()

 

    {

    }

 

 

    public void SetProperties(Control parent)
    {

 

 

        foreach (Control c in parent.Controls)

 

        {

 

            if

(c.ID == null && c.GetType().ToString().Equals("System.Web.UI.WebControls.Button"))

 

            {

                

((Button)c).Click += new EventHandler(BuildUiProperties_Click);

 

                ((

Button)c).Text = "Add New Users";

 

            }

 

    }

 

 

    public void BuildUiProperties_Click(object sender, EventArgs e)

 

    {

         //Do stuff

    }
}




Doing it this way, will cause the button click event to be fired when clicked.





Tags
Dock
Asked by
El-Sheikh
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Robert
Top achievements
Rank 1
Share this question
or