AsyncPostBackTrigger programmatically

Last post 07-12-2007 6:15 AM by Jonathan Shen – MSFT. 7 replies.

Sort Posts:

  • AsyncPostBackTrigger programmatically

    07-07-2007, 4:27 PM
    • Loading...
    • kojoh
    • Joined on 04-29-2007, 12:08 PM
    • Posts 60

    Hi.

    As the Title How can I decalre AsyncPostBackTrigger  to a button programmatically?

    Regards.

     

  • Re: AsyncPostBackTrigger programmatically

    07-07-2007, 6:23 PM
    • Loading...
    • apoorvs
    • Joined on 10-23-2006, 7:10 AM
    • Posts 1

            /// <summary>
            /// OnLoad EventHandler for ImageButton
            /// </summary>
            /// <param name="sender">Image Button</param>
            /// <param name="e">Event Arguments</param>
            protected void ImageButton_OnLoad(object sender, EventArgs e)
            {
                try
                {
                    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
                    trigger.ControlID = (sender as ImageButton).UniqueID;
                    trigger.EventName = "EventName"; //like "Click", "IndexChanged", etc.
                    this.UpdatePanelYours.Triggers.Add(trigger);
                }
                catch
                {
                    //Your exception management
                }
            }

  • Re: AsyncPostBackTrigger programmatically

    07-07-2007, 6:45 PM
    • Loading...
    • kojoh
    • Joined on 04-29-2007, 12:08 PM
    • Posts 60

    Hi, Thank's for replay. I'v use this code but it don't work!!

     

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script runat="server">
            protected void ImageButton1_Load(object sender, EventArgs e)
            {            
                    try
                    {
                        AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
                        trigger.ControlID = (sender as ImageButton).UniqueID;
                        trigger.EventName = "Click";
                        this.UpdatePanel1.Triggers.Add(trigger);
                    }
                    catch
                    {
    
                    
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
            <ContentTemplate>
            <%=DateTime.Now  %>
            </ContentTemplate>
                
            </asp:UpdatePanel>
          </div>
            <asp:ImageButton ID="ImageButton1" runat="server" OnLoad="ImageButton1_Load"  />
        </form>
    </body>
    </html>
    
     
  • Re: AsyncPostBackTrigger programmatically

    07-08-2007, 6:07 AM
    • Loading...
    • boj
    • Joined on 07-07-2007, 3:38 PM
    • Posts 4

     Remove the empty catch block to see what's happening or put an throw; there.

  • Re: AsyncPostBackTrigger programmatically

    07-11-2007, 6:15 AM

    Hi kojoh,

    Has your problem been resolved yet?  If resolved , please tell us the truth.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: AsyncPostBackTrigger programmatically

    07-11-2007, 12:15 PM
    • Loading...
    • kojoh
    • Joined on 04-29-2007, 12:08 PM
    • Posts 60

    No Not yet , I excute the code above but it dosen't solve my problem.

    is there any suggestions?

    Regards.

     

  • Re: AsyncPostBackTrigger programmatically

    07-11-2007, 4:30 PM

    Try put this code in the Page Load event instead of the Button Load:

    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
    trigger.ControlID = Button.UniqueID;
    trigger.EventName = "EventName"; //like "Click", "IndexChanged", etc.
    this.UpdatePanelYours.Triggers.Add(trigger);

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    http://weblogs.asp.net/rashid/
  • Re: AsyncPostBackTrigger programmatically

    07-12-2007, 6:15 AM
    Answer

    Hi kojoh,

    Have your problem resolved yet?  I have wrote a sample and it works fine in my pc.You can wholly copy the code into a blant page.Hope it helps.

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Reflection" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        //use refrection to register a asyncpost button here.
        private static MethodInfo triggerInitMethod = typeof(UpdatePanelTrigger).GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance);
        protected void Page_Load(object sender, EventArgs e)
        {
    
                AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
                trigger.ControlID = this.Button1.UniqueID;
                trigger.EventName = "Click";
                this.UpdatePanel1.Triggers.Add(trigger);
    
                if (ScriptManager.GetCurrent(this).IsInAsyncPostBack)
                {
                    triggerInitMethod.Invoke(trigger, null);
                }
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <%=DateTime.Now.ToString() %>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                    <%=DateTime.Now.ToString() %>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </form>
    </body>
    </html>
     
     

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (8 items)
Microsoft Communities
Page view counter