0
votes

I know its been asked before but I cannot get the event to fire even if Im creating the buttons and events each OnInit. Im doing a Sharepoint 2010 web part and fill a radiobuttonlist with values and add a submit button to the web part each time OnInit gets called. The Page_Load method is empty. I also tried putting the paintQnA call in an overridden CreateChildControls with the same result.

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        ...//Get data needed to create gui

        paintQnA(dr, dt, currentRow);
    }

    void paintQnA(DataRow dr, DataTable dt, int currentRow)
    {
        Panel p = new Panel();
        p.ID = currentRow.ToString();

        Label lbl= new Label();
        lbl.Text = dr["Title"].ToString();

        RadioButtonList rbl = new RadioButtonList();
        rbl.ID = currentRow.ToString() + "1";

        HtmlButton submitBtn = new HtmlButton();
        submitBtn.ID = currentRow.ToString();
        submitBtn.InnerText = "Click";
        submitBtn.ServerClick += new EventHandler(submitBtn_Click);

        ...//fill the radiobuttonlist with data

        this.Controls.Add(p);
        p.Controls.Add(lbl);
        p.Controls.Add(rbl);
        p.Controls.Add(submitBtn);

        UpdatePanel1.ContentTemplateContainer.Controls.Add(p);
    }

    void submitBtn_Click(object sender, EventArgs e)
    {
        ...//Should display another dynamically created panel but is never reached.
    }
2
any reason for using HtmlButton instead of Button object? - user1
Not really. Just tried it with a Button if there should be any difference, still no luck though. - mdc
did you try using submitBtn.Click instead of submitBtn.ServerClick? - user1

2 Answers

1
votes

Found the error:

p.ID = currentRow.ToString();
submitBtn.ID = currentRow.ToString();

They have the same ID...they can't have the same ID.

1
votes

In your code I can see you are assigning the same ID to Panel and submitBtn. So due to duplicate Id, your click event is not fired.

Try different IDs for Panel and Submitbutton then It should work fine!