Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to add imagebutton in asp.net linkButton?

Posted on 2011-10-25
8
Medium Priority
?
286 Views
Last Modified: 2012-05-12
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());
0
Comment
Question by:programmerist
  • 4
  • 3
8 Comments
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 37022847
Hi!
What is the purpose of putting button inside button? Why not just use ImageButton? I guess the result will be the same.
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 37022849
Try like this


LinkButton1.Controls.Add(new ImageButton(){ImageUrl='your_url', ID = 'btnImg'});
0
 

Author Comment

by:programmerist
ID: 37023198
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 37023315
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
 

Author Comment

by:programmerist
ID: 37023567
ok. i can not see image button in link button...
0
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 37023792
To add image button inside link button you should change
PlhControl.Controls.Add(_btnSave);
to
btnSave.Controls.Add(_btnSave);
0
 

Author Comment

by:programmerist
ID: 37119730
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
 

Author Comment

by:programmerist
ID: 37119731
vaz geçtim vazzzzzzzzzzzzzzzzzzzzzzzzzz
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question