Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET Data-Binding
I'm trying to fire the Click event of the linkbutton placed inside a datalist,and i'm using the following code
 

ASPX Page
 

<asp:LinkButton ID="LinkButton1" runat="server" Font-Names="Bertham" Font-Size="X-Large"
                            Font-Underline="False" CommandName = "answer">"<%#Eval ("Question") %>"</asp:LinkButton>
 
Code Behind Page
 
protected void DataList1_ItemCommand(object source,System.Web.UI.WebControls.DataListCommandEventArgs e)
   {
       if (e.CommandName == "answer")
   {
       Response.Write("<script language = "'javascript'">alert('U Clicked The Linkbutton'</script>)");
       Response.Write("Hello");
       //Response.Write("Hello");
   }
   }
but its not working....
Can Anyone help me. I think this is a big problem 2 many. Which I found on net while trying to sought out the problem by myself.
 
Thanks In Advance....
Posted 4-Jun-12 2:32am
Edited 4-Jun-12 2:33am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if you have only one condition, you can remove if , and do this on grid databound event , because when you use item command it post back and after it response you.
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            LinkButton btn = (LinkButton) FindControl("lnkbtn");
            btn.Attributes.Add("onclick","alert(you are leaving this page!)");
        }
  Permalink  
Comments
Arjun YK at 5-Jun-12 0:22am
   
Thank u for the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 4 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100