I'm w开发者_Go百科orking on an asp.net app and I have some controls that are created dynamically 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 unable 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?
Edit:
This is my script 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);
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
<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
精彩评论