0

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.
    }
3
  • any reason for using HtmlButton instead of Button object? Commented Jun 11, 2013 at 15:23
  • Not really. Just tried it with a Button if there should be any difference, still no luck though. Commented Jun 11, 2013 at 15:33
  • did you try using submitBtn.Click instead of submitBtn.ServerClick? Commented Jun 11, 2013 at 16:38

2 Answers 2

1

Found the error:

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

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

Sign up to request clarification or add additional context in comments.

Comments

1

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.