how to add imagebutton in asp.net linkButton?

How to do that dynamically C# ?


    <asp:LinkButton ID="LinkButton1" runat="Server" >Text
<asp:ImageButton ID="ImageButton1" runat="Server" ImageUrl="~/images/Detail.png"></asp:ImageButton>
</asp:LinkButton>
Forexample:


LinkButton lnk = new LinkButton();
lnk.Add(new ImageButton());
programmeristAsked:
Who is Participating?
 
Kiran SonawaneProject LeadCommented:
Try like this


LinkButton1.Controls.Add(new ImageButton(){ImageUrl='your_url', ID = 'btnImg'});
0
 
ivan_vaguninCommented:
Hi!
What is the purpose of putting button inside button? Why not just use ImageButton? I guess the result will be the same.
0
 
programmeristAuthor Commented:
NOT WORKING:

  ImageButton _btnSave = new ImageButton();
            _btnSave.ID = Guid.NewGuid().ToString();
            _btnSave.AlternateText = "fsfsf";
            _btnSave.Click += new ImageClickEventHandler(btnSave_Click);
            _btnSave.Attributes.Add("runat", "server");
            _btnSave.ImageUrl = "~/images/Ok.png";
         
            LinkButton btnSave = new LinkButton();
            btnSave.ID = Guid.NewGuid().ToString();

            PlhControl.Controls.Add(_btnSave);
            btnSave.Text = "Test";
            btnSave.Attributes.Add("runat", "server");
            btnSave.Click += new EventHandler(btnSave_Click);
            PlhControl.Controls.Add(btnSave);
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
ivan_vaguninCommented:
No need to add runat="server". When create controls dynamically.
What is PlhControl? And what do you mean by "NOT WORKING"? Button handler not executed? This is because you change button ID on every postback (_btnSave.ID = Guid.NewGuid().ToString()) - so page does not who initiated the event and can't execute proper handler. You should keep ID constant between postbacks: _btnSave.ID = "MySaveButton";
0
 
programmeristAuthor Commented:
ok. i can not see image button in link button...
0
 
ivan_vaguninCommented:
To add image button inside link button you should change
PlhControl.Controls.Add(_btnSave);
to
btnSave.Controls.Add(_btnSave);
0
 
programmeristAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for programmerist's comment http:/Q_27413611.html#37023567

for the following reason:

ananin ami
0
 
programmeristAuthor Commented:
vaz geçtim vazzzzzzzzzzzzzzzzzzzzzzzzzz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.