Adding Programmatically Buttons to an asp.net page...
-
Hello , my problem is that i added some buttons Programmatically and i don't want them to postback the page .. just walla execute the javascriptcode how can i desactivate this property : ps: buttons are in a panel with : runat="server".
foreach (Promotion promotion in promotions) { button = new Button(); button.ID = **"button"** + i; button.CssClass = "ContextMenuItem"; button.OnClientClick = **"javascript:function(this);"**; i++; button.Text = promotion.Value.ToString(); ValueListPanel.Controls.Add(button); }
-
Hello , my problem is that i added some buttons Programmatically and i don't want them to postback the page .. just walla execute the javascriptcode how can i desactivate this property : ps: buttons are in a panel with : runat="server".
foreach (Promotion promotion in promotions) { button = new Button(); button.ID = **"button"** + i; button.CssClass = "ContextMenuItem"; button.OnClientClick = **"javascript:function(this);"**; i++; button.Text = promotion.Value.ToString(); ValueListPanel.Controls.Add(button); }
-
Hello , my problem is that i added some buttons Programmatically and i don't want them to postback the page .. just walla execute the javascriptcode how can i desactivate this property : ps: buttons are in a panel with : runat="server".
foreach (Promotion promotion in promotions) { button = new Button(); button.ID = **"button"** + i; button.CssClass = "ContextMenuItem"; button.OnClientClick = **"javascript:function(this);"**; i++; button.Text = promotion.Value.ToString(); ValueListPanel.Controls.Add(button); }
Hi, 1) If you need the asp.net button only then - Make sure your Javascript function returns false or write like this
button.OnClientClick = "javascript:function(this); return false;";
-
If you can use a HtmlButton then -
HtmlInputButton somebuttonhtml = new HtmlInputButton();
somehtmlbutton.ID = "somehtmlbutton";
somehtmlbutton.Value = "ContextMenuItem";
somehtmlbutton.Attributes.Add("onclick", "javascript:function(this);")
ValueListPanel.Controls.Add(somehtmlbutton);
I suggest to use HtmlButton as it satisfies your requirement and it is light weight. Hope this will help. Thanks, Padmanabh
-