asp.net linkbutton in updatepanel doesn't fire

后端 未结 1 1442
一个人的身影
一个人的身影 2021-01-18 11:58

I have a asp.net web application. In my .aspx page I have a update panel in which I have 3 asp:LinkButton that should make a call to a c# code behi

1条回答
  •  遇见更好的自我
    2021-01-18 12:43

    You're very close. Couple of things:

    • Your triggers should be AsyncPostBackTriggers as you said you tried.
    • Your triggers need an event name.
    • Suggestion: This won't prevent your events from firing, but unless you want EVERY postable event to cause a postback, add UpdateMode="Conditional" to your UpdatePanel.

    Here is a working example.

    Web Form - WebForm1.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AspDotNetStorefront.WebForm1" %>
    
    
    
    
        
            
        
        
            
    • Never clicked

    CodeBehind - WebForm1.aspx.cs:

    using System;
    
    namespace AspDotNetStorefront
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            private static int _clickedCount = 0;
    
            protected void lnk1_Click(object sender, EventArgs e)
            {
                ++_clickedCount;
                var suffix = _clickedCount <= 1 ? "time" : "times";
                lnk_1.Text = string.Format("Clicked {0} {1}", _clickedCount, suffix);
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题