I was trying to create "asp:buttons" dynamically with special asp tags (<%%>) as I am using a loop in the codebehind to generate x amount of buttons based on the database. However, when the special tag tries to write out the asp button, the button does not work.
I know that the problem is due to it not converting when it's being written out.
For example, when I view source an asp button is suppose to look like this:
<input type="submit" name="ctl00$ContentPlaceHolder1$Button1" value="Hello" id="ContentPlaceHolder1_Button1" class="button" style="color:White;background-color:Transparent;border-style:None;" />
but the asp button being written on the view source was shown as:
<asp:Button ID='Button1' CssClass='button' BackColor='Transparent' runat='server' BorderStyle='None' ForeColor='white' Text='Hello' OnCommand='Button1_Click' CommandArgument='cat0002' />
If there are other ways to create the buttons please do recommend me too as I have to create them dynamically while trying to display them in the individual table data I created. And I would need to pass the values through to the code behind as I have to call the SQL database when its clicked.
try it:
protected void Page_Load()
{
Button ButtonChange = new Button();
ButtonChange.Text = "New Button";
ButtonChange.ID = "btnNew_" + i.ToString();
ButtonChange.Font.Size = FontUnit.Point(7);
ButtonChange.ControlStyle.CssClass = "button";
ButtonChange.Click += new EventHandler(test);
}
more info : http://msdn.microsoft.com/en-us/library/kyt0fzt1.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.