programmatically adding buttons and OnClientClick but still having post back issue

idkl1914

New Member
I am trying to hide some divs using Javascript but i think the post back keeps reloading the page.To make things more complicated my buttons are added programmatically by my code behind.\[code\]foreach (string line in thefilters) { Button newButton = new Button(); newButton.ID = Convert.ToString(line); newButton.Text = Convert.ToString(line); newButton.CssClass = "tblbutton"; //newButton.Attributes.Add("onclick", "hide_div("+newButton.ID+")"); newButton.OnClientClick = "return hide_div('" + newButton.ID + "')"; pnl_left.Controls.Add(newButton); }\[/code\]My javascript is located in the header as follows.\[code\]<script type="text/javascript"> function hide_div(filter) { var pnl_right = document.getElementById("pnl_right"); var listofelements = pnl_right.getElementsById("div"); for (var i = 0; i < listofelements.length; i++) { if (listofelements.id.indexOf(filter) == 0) { document.getElementById(listofelements.id).style.display = 'inline'; } else { document.getElementById(listofelements.id).style.display = 'none'; } } return false; }\[/code\]I may have issues in the javascript for what i want to achieve but i am confident that if i can stop the postback then i can solve the javascript myself..Thanks for any suggestions in advance.
 
Back
Top