Link to home
Start Free TrialLog in
Avatar of programmerist 1983
programmerist 1983Flag for Türkiye

asked on

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());
Avatar of Member_6283346
Member_6283346

Hi!
What is the purpose of putting button inside button? Why not just use ImageButton? I guess the result will be the same.
ASKER CERTIFIED SOLUTION
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of programmerist 1983

ASKER

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);
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";
ok. i can not see image button in link button...
To add image button inside link button you should change
PlhControl.Controls.Add(_btnSave);
to
btnSave.Controls.Add(_btnSave);
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
vaz geçtim vazzzzzzzzzzzzzzzzzzzzzzzzzz