views:

29

answers:

2

Hi there.

I'm working on an asp.net app and I have some controls that are created dinamically on the OnInit event. One of that controls is an asp button that has been working fine until now. When I add a ScriptManager to my page, that same button is unnable to postback. It's only working if a take the ScriptManager out.

has anything like this ever appened to somebody else? Am I invalidating the page somehow?

Tks

ps: this is my scrip manager tag:

    <asp:ScriptManager ID="ScriptManager1" runat="server" 
EnablePageMethods="true" EnableScriptGlobalization="true" 
EnableScriptLocalization="true"> 
</asp:ScriptManager>

//My Dynamic Button:
Button button1 = new Button
            {
                ID = "button1",
                Text = "Ok"
            };
            button1.Click += new EventHandler(Button1_Click);
A: 
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" />
    <div>      
      <p id="lblClickedFlag" runat="server">
      </p>
      <div id="container" runat="server">
      </div>
    </div>
</form>


protected void Page_Init(object sender, EventArgs e)
{
    //My Dynamic Button:
    Button button1 = new Button
    {
        ID = "button1",
        Text = "Ok"
    };
    button1.Click += Button1_Click;
    container.Controls.Add(button1);
}

protected void Button1_Click(object sender, EventArgs e)
{
    lblClickedFlag.InnerText = "clicked";
}


this works for me
Oleg Kalenbet
A: 

Ok, one weird thing. Havent figured it out the reason I'm having this behaviour, but, if the button is inside a container, say, a table cell, then it's able to post back. Might be a workaround

DJPB