I want to create a button dynamically (image, image button or simple button) to show text and image both, in asp.net using C# . But I am not able to do it because its shows either image property or text property. How to do it please help me.

you can create the button with text and set image as the background for the button and apply some styles to the button inorder to display correctly.

Example:

Button btn1 = new Button();
btn1.Text = "sample";
btn1.Style.Add("background-image", "url(images/sample.gif)");
btn1.CssClass = "imgbutton";

css class:

.imgbutton
{
    cursor:pointer;
    background-repeat:no-repeat; 
    background-position:left;
    padding-left:30px; 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.