Causing postback

Last post 11-29-2006 8:54 AM by ncipollina. 11 replies.

Sort Posts:

  • Causing postback

    11-22-2006, 10:30 AM
    • Member
      510 point Member
    • aspBOD
    • Member since 01-21-2005, 11:11 AM
    • Posts 118

    I have written some javascript that async calls a webservice every second. If the service returns true, I want to cause a postback, with client script that can be handled on the server and tell a particular update panel to update in the server side handler.
     
    I also wish to construct event arguments on the client to be passed as part of the post back.

    How do I do this? 

  • Re: Causing postback

    11-22-2006, 1:11 PM
    • Member
      356 point Member
    • ncipollina
    • Member since 10-20-2006, 7:36 AM
    • Richmond, VA USA
    • Posts 79

    I need to do something similar, and I'm wondering if you could do it by having your page implement the IPostBackEventHandler.  This interface requires that you implement a RaisePostBackEvent method.  This method takes a string argument, and you could update your updatepanels in this method.  Does anyone know if this approach would work?

     

    Thanks,

     

    Nick 

  • Re: Causing postback

    11-22-2006, 6:13 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs

    hello.

    ipostbackeventhandler is not the answer if you need to update updatepanels. what you could do is:

    1. use the postbackaction

    2. add a hidden dummy  button to the updatepanel and force the submit by calling its click method

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Causing postback

    11-23-2006, 4:02 AM
    • Member
      510 point Member
    • aspBOD
    • Member since 01-21-2005, 11:11 AM
    • Posts 118

    Nope, dont need to do that. ipostbackeventhandler is the way to go. 

     

    I add some javascript to the page via:

     

      Microsoft.Web.UI.ScriptManager.RegisterClientScriptBlock(
                this,
                this.GetType(),
                "UIService_Agent",
                string.Format(                   
                    "function CheckAgentTimer()" +
                    "{{" +
                        "UIService.ShouldInteruptAgent(OnAgentTimerSucceeded,OnAgentTimerFailure);" +
                    "}}" +
                    "function OnAgentTimerSucceeded(result)" +
                    "{{" +
                        "if(eval(result))" +
                        "{{" +
                            "{0};" +
                        "}}" +
                        "setTimeout(\"CheckAgentTimer()\",{1});" +                  
                    "}}" +
                    "function OnAgentTimerFailure()" +
                    "{{" +
                        "setTimeout(\"CheckAgentTimer()\",60000);" +
                    "}}" +
                    "setTimeout(\"CheckAgentTimer()\",10000);",
                    this.Page.ClientScript.GetPostBackEventReference(this,AgentTasksTimer.AGENT_PROCESS),
                    this.timerInterval
                    ),
              true);

     and then I implement the interface ipostbackeventhandler

     


        public void RaisePostBackEvent(string eventArgument)
        {
            if (eventArgument == AGENT_PROCESS)
            {
                //Is There Work for the Agent?
                if (WorkItemActionRequired != null && IsWorkItemActionRequired())
                {
                    WorkItemActionRequired(this, new WorkItemEventArgs(ResourceReceiverService.GetUserWork(((IUserPrincipal)Context.User).Credentials.UserId, true)));
                }  
            }
        }   

    Messy I know, but bare with me....
     

    You can then request that update panels are updated on the server i.e. myUpdatePanel.Update

     This works!

     

  • Re: Causing postback

    11-28-2006, 1:49 PM
    • Member
      356 point Member
    • ncipollina
    • Member since 10-20-2006, 7:36 AM
    • Richmond, VA USA
    • Posts 79
    Luis Abreu:

    hello.

    ipostbackeventhandler is not the answer if you need to update updatepanels. what you could do is:

    1. use the postbackaction

    2. add a hidden dummy  button to the updatepanel and force the submit by calling its click method

     

    How do you call the click method on a hidden dummy button? 

  • Re: Causing postback

    11-28-2006, 4:26 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello.

    you must get  a refernce for the html control and call its click method:

    $get("your_button_client_side_id").click();
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Causing postback

    11-28-2006, 4:40 PM
    • Member
      356 point Member
    • ncipollina
    • Member since 10-20-2006, 7:36 AM
    • Richmond, VA USA
    • Posts 79

    But will this cause a partial or full post back?

     

    Thanks,

    Nick 

  • Re: Causing postback

    11-28-2006, 4:44 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello.

    it depend: if it's an asp.net button and it's placed inside an updatepanel (or if it's outside the updatepanel but it's configured as a trigger) you'll get a partial postback.
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Causing postback

    11-28-2006, 4:58 PM
    • Member
      356 point Member
    • ncipollina
    • Member since 10-20-2006, 7:36 AM
    • Richmond, VA USA
    • Posts 79

    That might do the trick then.  Right now I have implemented IPostBackHandler, but it causes a full post-back.  I just want to do a partial.  How do I make the button invisible, set Visible to false, or set visible to hidden in the button style?

     

    Thanks,

     

    Nick 

  • Re: Causing postback

    11-28-2006, 5:04 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello.

    it depend: if it's an asp.net button and it's placed inside an updatepanel (or if it's outside the updatepanel but it's configured as a trigger) you'll get a partial postback.
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Causing postback

    11-28-2006, 5:05 PM
    • All-Star
      25,662 point All-Star
    • Luis Abreu
    • Member since 02-12-2005, 6:22 AM
    • Madeira [Portugal]
    • Posts 5,368
    • TrustedFriends-MVPs
    hello again.
    well, i'd just add syle="display:none" in the asp.net button declaration.
    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • Re: Causing postback

    11-29-2006, 8:54 AM
    • Member
      356 point Member
    • ncipollina
    • Member since 10-20-2006, 7:36 AM
    • Richmond, VA USA
    • Posts 79

    This will also allow me to put code server-side?

     

    Thanks,

    Nick 

Page 1 of 1 (12 items)
Microsoft Communities