ModalPopup control and code-behind postback

Last post 07-06-2009 3:39 AM by newpat. 19 replies.

Sort Posts:

  • ModalPopup control and code-behind postback

    08-29-2006, 7:10 AM
    • Member
      15 point Member
    • KalleKlovn
    • Member since 08-28-2006, 8:00 AM
    • Posts 3
    Is it posible to have a ModalPopup control to post back and invoke a method in a code-behind class. In the example I have seen it only execute a javascript for the "onOK" button of the popup, I want to execute som c# code on "onOK". Is it possible?
  • Re: ModalPopup control and code-behind postback

    08-29-2006, 2:55 PM
    • Contributor
      4,198 point Contributor
    • Ted Glaza [MSFT]
    • Member since 04-12-2006, 11:51 PM
    • Microsoft
    • Posts 847
    • AspNetTeam
    Hi KalleKlovn,

    Yes - it's deceptively simple.  Just ignore the OnOKScript property and add a regular ASP.NET server side OnClick handler to your OK button.

    Thanks,
    Ted
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Filed under:
  • Re: ModalPopup control and code-behind postback

    08-29-2006, 7:11 PM
    • Member
      5 point Member
    • tolakc
    • Member since 08-29-2006, 10:53 PM
    • Posts 1

    I am new to the Atlas toolkit so please bear with me.  I have a checkbox list residing within a ModalPopup control.  The user can check of boxes and then click an Add To List button that fires a server-side function to add the values of those boxes to that user's profile.  The control posts back just fine but the updated status of the checkbox list is not being sent back (e.g. none of the checkboxes are selected).  What am I doing wrong?

  • Re: ModalPopup control and code-behind postback

    09-01-2006, 3:28 PM
    • Contributor
      4,198 point Contributor
    • Ted Glaza [MSFT]
    • Member since 04-12-2006, 11:51 PM
    • Microsoft
    • Posts 847
    • AspNetTeam

    Hi tolakc,

    I can't really tell why this is happening from the information you've provided.  Is the checkbox list inside an UpdatePanel with your button?  Are you using an UpdatePanel at all to do this, or just regular postbacks?  Perhaps you can post a small sample showing exactly what's going on.

    Thanks,
    Ted

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: ModalPopup control and code-behind postback

    09-28-2006, 1:52 PM
    • Member
      25 point Member
    • woodchuck
    • Member since 09-28-2006, 5:38 PM
    • Posts 5

    I've been reading post after post on this subject and I'll give you a quick rundown of what I'm trying to do.  The user clicks on a link and the modal popup window appears.  It has a form on it that the user fills out.  When they click the Ok button, I've created a btnOk_Click event handler and added code to take the variables from the modal popup and add the values to the Session object.  The last line in the handler is to redirect to the next page that uses the variables.  I've tried to debug it by putting a breakpoint in the handler, but it never hits the breakpoint.  I've looked into calling the btnOk_Click handler via Javascript, but I can't figure it out.

     Any Suggestions?

    Thanks,

    Eric
     

  • Re: ModalPopup control and code-behind postback

    09-28-2006, 5:03 PM
    • Member
      73 point Member
    • Thunder3
    • Member since 08-18-2006, 3:17 PM
    • Posts 30

    I had similar issues with this (we use VB.NET in our shop, it may be different in C#).

     

    I found that in order to make the button handler fire, you need to associate the UniqueID of the button to the target argument of the postback, instead of the ID or the ClientID.

     Not sure if this will help you.

    I used the following script:


    function postbackFromJS(sender, e) {
                var postBack = new Sys.WebForms.PostBackAction();
                postBack.set_target(sender);    
                postBack.set_eventArgument(e);
                postBack.performAction();
            }

    Then in the codebehind (on PageLoad)

     postbackButton.OnClientClick = String.Format("postbackFromJS('{0}', '{1}')", postbackButton.UniqueID, "")

  • Re: ModalPopup control and code-behind postback

    09-28-2006, 5:52 PM
    • Member
      25 point Member
    • woodchuck
    • Member since 09-28-2006, 5:38 PM
    • Posts 5

    Thunder3,

    Thanks a ton for your post!  I did what you did and now I can reach the event handler in debug mode!  The values were passed through to the Session object, but I'm still having a problem with the final line:

             Response.Redirect("FileUpload.aspx");

    Nothing happens at this point and I am returned to the original page with the modal popup link.  Why am I not redirected to the next page?

    Thanks,

    Eric 

  • Re: ModalPopup control and code-behind postback

    09-28-2006, 6:13 PM
    • Member
      25 point Member
    • woodchuck
    • Member since 09-28-2006, 5:38 PM
    • Posts 5

    Thunder3,

    Another thing that I just discovered.  I put a breakpoint in the OnInit method for the "FileUpload.aspx" page and it was called.  So from what I can figure, the redirect is working properly, there is just something else that is taking me back to the original page.

     Any thoughts?

    Thanks,

    Eric
     

  • Re: ModalPopup control and code-behind postback

    09-29-2006, 8:40 AM
    • Member
      73 point Member
    • Thunder3
    • Member since 08-18-2006, 3:17 PM
    • Posts 30

    You may want to ensure that your Response.Redirect is not in a Try Catch block. Sometimes that can mess things up, especially with Sessions.

     

    There may also be a condition on your other page that you have forgotten about that redirects back?


    If you continue to have problems, try registering a redirect script block (javascript) onto the first page after you do the client side postback. This will ensure that the server performs a full round-trip (and stops doing funny stuff).

    (Something like this):

    function ProcessOrder()
    {
        location.href = "ProcessOrder.aspx";
    }
    setTimeout("ProcessOrder()", 1000);

     

    I wouldn't go down this route unless its the only thing left though, it's not overly clean.

    Perhaps try Server.Transfer as well. 

  • Re: ModalPopup control and code-behind postback

    09-29-2006, 1:09 PM
    • Member
      32 point Member
    • darthg8r
    • Member since 08-04-2005, 1:52 PM
    • Posts 6

    I've trying to do the same thing with the modal dialog box posting back through an updatepanel.  In IE, the event fires in code behind, but a javascript error occurs.  Line:1 Char: 1  Error:  Object expected.  Then the button I use to open the dialog box stops functioning.  In Firefox, I get the code behind to run, no javascript error, but the button doesn't work again.  Awefully close here, but not quite.  Maybe a little more help?

     

    Rick

  • Re: ModalPopup control and code-behind postback

    09-29-2006, 4:45 PM
    • Member
      73 point Member
    • Thunder3
    • Member since 08-18-2006, 3:17 PM
    • Posts 30

    To be honest, I haven't tried the modal inside an updatepanel yet.

    If you are getting a JS error in IE, it is likely that you are in FF as well, it is just not showing up because FF natively suppresses JS errors (they will appear in the Javascript console instead).

    The error you are getting may be due to an error thrown on the server side. I think that they pass through the updatepanel and display as JS errors (I was having this for an incorrect key index problem earlier today).

     

    Try stepping through right to the point it returns to the client to be sure it isn't a different part of your code blowing up. 

  • Re: ModalPopup control and code-behind postback

    01-07-2007, 7:09 PM
    • Member
      2 point Member
    • darrenarbell
    • Member since 01-07-2007, 10:59 PM
    • Posts 1

    Did you resolve this problem? I'm receiving the same error within IE. Within FF I get Error: Sys.WebForms.PostBackAction is not a constructor. Which makes me think that it can find the libraries. Would this be correct and if so how would I reolve it? I new to this whole thing, so at the minute I'm just guessing.

  • Re: ModalPopup control and code-behind postback

    02-06-2007, 4:25 PM
    • Member
      39 point Member
    • prieckmann
    • Member since 08-11-2006, 1:24 PM
    • Montreal
    • Posts 8

    In the release version of Ajax, the PostBackAction is not in the Sys.WebForms namespace.
    It was transfered to the Microsoft.Web.Preview.dll (Futures January CTP).

    To use it,

    - Install the ASP.NET 2.0 AJAX Futures January CTP.
    - Reference it in your project.
    - Reference it in the ScriptManager :

    <asp:ScriptManager ID="ScriptManager1" runat="server" >
    <Scripts>
    <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
    </Scripts>
    </asp:ScriptManager>

    - Call Sys.Preview.PostBackAction() instead

    Hope it helps.

  • Re: ModalPopup control and code-behind postback

    05-02-2007, 7:41 AM
    • Member
      10 point Member
    • alijohn
    • Member since 05-02-2007, 11:23 AM
    • Newcastle Upon Tyne, UK
    • Posts 5

    Hi Guys,

    I am using AJAX.NET 2.0 with Visual Web Developer.

    My site has a master page. I have tried several different way to fire post back event on a Yesbutton click in modalpopup windows but no use.

    I have also tried UniqueID method but no use always get the 'Error on Page'.

    I have also tried to reference the button with 'ctl00_ContentPlaceHolder1_YesButton' in set_target method.

    The Modalpopup windows code is as follows:

    <asp:Panel ID="ConfirmtionPanel" runat="server" CssClass="modalPopup" Style="display: none">

    <div class="modalPopup-text">

    Are you sure you want to delete this item?

    <br />

    <br />

    <asp:Button ID="YesButton" runat="server" Text="Yes" OnClick="YesButton_Click" />&nbsp;&nbsp;

    <asp:Button ID="NoButton" runat="server" Text="No" />

    </div>

    </asp:Panel>

    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="DeleteButton"

    PopupControlID="ConfirmtionPanel"

    BackgroundCssClass="modalBackground"

    OkControlID="YesButton"

    OnOkScript="onYes()"

    CancelControlID="NoButton"

    DropShadow="true" >

    </ajaxToolkit:ModalPopupExtender>

     

    The script code is as follows:

    <script type="text/javascript">

    function

    onYes() {

    var postBack = new Sys.Preview.PostBackAction();

    postBack.set_target(

    'YesButton');

    postBack.set_eventArgument(

    '');

    postBack.performAction();

    }

    </script>

     

    On Page Load:

     Page.ClientScript.GetPostBackEventReference(Me, String.Empty)

     

    Thanks in Advance

     

  • Re: ModalPopup control and code-behind postback

    05-02-2007, 2:26 PM
    • Contributor
      2,610 point Contributor
    • kirtid
    • Member since 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • AspNetTeam

    Do not set the OKButtonID to be the yes button and do not set the onok script. By setting that the modalpopup prevents the postback and just executes the onok script if set and hides the popup. 

    OkControlID="YesButton"

     

    OnOkScript="onYes()"

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 2 (20 items) 1 2 Next >