Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created link button in my application now i have binded the event handler to it but its not Firing any suggestion.
Posted
Comments
bbirajdar 18-Oct-12 7:05am    
"not Firing any suggestion" ..How can it fire a suggestion ?
adriancs 18-Oct-12 8:10am    
I think that simply a grammar mistake and the sentences sounds to be like this:
......but its not Firing. Any suggestion?
AshishChaudha 18-Oct-12 7:06am    
share your code please..
adriancs 18-Oct-12 8:11am    
how do you "bind the event handler"?
bbirajdar 18-Oct-12 9:51am    
using += operator...

First Add Your link Button and Div message in .ASPX
<asp:LinkButton ID="ancDelete" CommandName="delete" OnCommand="delete_EventCategories" runat="server">Delete </asp:LinkButton>

XML
<div id="divMessage" runat="server" class="grid_7 alpha" style="display: none;">
        <asp:Literal runat="server" ID="ltlMessage" Text="test"></asp:Literal>
    </div>

Then write a Show method.
C#
public static void ShowMessage(string _class, string msg, System.Web.UI.HtmlControls.HtmlGenericControl divMessage, Literal ltlMessage)
       {
           divMessage.Style.Add("display", "block");
           divMessage.Attributes.Add("class", _class);
           ltlMessage.Text = msg;
       }

And finally Event Hadelers.
C#
protected void delete_EventCategories(object Sender, CommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                try
                {

             ShowMessage("alert alert-success", " Successfully!",divMessage, ltlMessage);
                }
                catch (Exception ex)
                {

                  ShowMessage("alert alert-error", ex.InnerException.Message, divMessage,ltlMessage);
                }
            }
        }
 
Share this answer
 
If it is matter of dynamic link control then just mind it that its state not persist my ASP.net framework with the help of view state. For example if you create a link button like as follows
ASP.NET
<div id="divLink"  runat="server">
</div>

C#
if (!base.IsPostBack)//comment out this condition if you want to fire Click event 
{
    var control = new LinkButton();
    control.Text = "Clik ME";           
    control.Click += control_Click;
    divLink.Controls.Add(control);
}

C#
void control_Click(object sender, EventArgs e)
{
    Response.Write("............................");
}

You see that next postback event the LinkButton not showing and event not firing.
If you want to fire that event you need to create that dynamic control every request (either postback or not postback.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900