disable "cause validation" for dynamically created buttons
<p>I am creating the same button twice: once on Page_Load, and another on: Page_PreRender. 
I expected to see the same behavior, however, the buttons created on Page_PreRender doesn't work the way intended. (i.e. property "causeValidation" remains true).  </p>

<p>"I want to disable "causeValidation" for the button in page_preRender, and i want it there in PreRender. Also, I want the Button_Click function to execute for both buttons, currently it does only for button created on "Page_load" ".</p>

<p>I am looking for a <strong>solution or an explanation</strong> for this behavior.</p>

<p>Thank You.</p>

<p>Take a look at the code: </p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {            
        form1.Controls.Add(GetButton("Button1", "Click"));
    }

    protected void page_PreRender(object sender, EventArgs e)
    {
        form1.Controls.Add(GetButton("Button3", "Click"));
    }

    private Button GetButton(string id, string name)
    {
        Button b = new Button();
        b.Text = name;
        b.ID = id;
        b.CausesValidation = false;
        b.Click += new EventHandler(Button_Click);
        b.OnClientClick = "ButtonClick('" + b.ClientID + "')";
        return b;
    }

    protected void Button_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptBlock(this.GetType(), ((Button)sender).ID, "&lt;script&gt;alert('Button_Click');&lt;/script&gt;");
        Response.Write(DateTime.Now.ToString() + ": " + ((Button)sender).ID + " was clicked");
    }
</code></pre>

<p>and here is the javascript:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    function ButtonClick(buttonId) {
        alert("Button " + buttonId + " clicked from javascript");
    }
&lt;/script&gt;
</code></pre>

<p><strong>Update:</strong>
let me add this: Both buttons execute the client's script. This means that buttons are created. "see function GetButton() ".</p>

<p>Also, the reason why i have the button created "on preRender" instead of "on Page_Load" is that: if i have a form used to enter data into a table <strong>dynamically</strong>, and i add the data on button click, the the page will PostBack first, then execute the event handler, (i.e the data is added to the table but will show on NEXT postBack). So, PreRender is used to show the table AFTER it is updated by the button_click event. </p>

<p>I hope this addition is useful</p>
