Solved

ModalPopupExtender execute code behind event HELP!

Posted on 2008-10-01
12
1,428 Views
Last Modified: 2013-12-17
Hi,

I am trying to fire out the modal popup to display and inform user that there are TBC values in the record.

If the user selects YES then it will carry on commiting the data etc... else stop everything.

I have implemented what I can, it executes the prompt when statement is true, which is what I want it to do, BUT when YES button is clicked, command is not doing what I want it to do. I have supplied code snippet (c#) to give you an idea what level I am at.

Note: the command I would like it to execute when YES clicked is:

        updateData();
        sendMail2();
        hardCopy();
        excelFile();
        DelLockSession();

Regards,

introlux

P.S
At the moment any time the button print is selected, it just does autopost back and nothing happens. It seems to get stuck on the screen with a refresh! So there is two problems. 1. it does not execute command and 2. it does not do anything when the button print is selected.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<div>
   <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" Width="233px">
       There are TBC values, do you wish to still continue?<br />
 
   <br />
   <div align="center">
      <asp:Button ID="OkButton" runat="server" Text="Yes" />
      <asp:Button ID="CancelButton" runat="server" Text="No" />
   </div>
   </asp:Panel>
   <br />
   
   <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
             TargetControlID="Button1"
             PopupControlID="Panel1"
             BackgroundCssClass="modalBackground"
             DropShadow="true"
             OkControlID="OkButton"
             OnOkScript="onOk()"
             CancelControlID="CancelButton" />
<asp:Button ID="Button1" runat="server" Text="Button" style="display:none" Visible="true" OnClick="Button1_Click" /></div>
 
----------------------------------------------------------------------
 
Code behind:
 
----------------------------------------------------------------------
 
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        if (opProStatusDrop.SelectedValue == "Closed")
        {
            if (CheckIFNull() == true)
            {
                if (!chkFQC.Checked || !chkIR.Checked) //(chkFQC.Checked == false || chkIR.Checked == false)
                {
                    lblStatus.Text = "You have not confirmed check box";
                }
                else
                {
                    updateData();
                    sendMail();
                    hardCopy();
                    excelFile();
                    DelLockSession();
                    Response.Redirect("SessPrint.aspx");
                }
            }
        }
        if (opProStatusDrop.SelectedValue == "Open - complete")
        {
            if (CheckIFNull() == true)
            {
                if (!chkFQC.Checked || !chkIR.Checked) //(chkFQC.Checked == false || chkIR.Checked == false)
                {
                    lblStatus.Text = "You have not confirmed final quota counts or final response rate";
                }
                else
                {
                    updateData();
                    sendMail2();
                    hardCopy();
                    excelFile();
                    DelLockSession();
                    Response.Redirect("SessPrint.aspx");
                }
            }
        }
        if (opProStatusDrop.SelectedValue == "Open - field")
        {
            if (CheckIFTBC() == false)
            {
                ModalPopupExtender1.Show();
            }
            else
            {
                updateData();
                sendMail2();
                hardCopy();
                excelFile();
                DelLockSession();
                Response.Redirect("SessPrint.aspx");
            }
        }
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        updateData();
        sendMail2();
        hardCopy();
        excelFile();
        DelLockSession();
    }

Open in new window

0
Comment
Question by:introlux
  • 6
  • 5
12 Comments
 
LVL 7

Expert Comment

by:ajolly
ID: 22613671
in javascript function onOk()

write following:

__doPostBack(''<%=Button1.UniqueId%>'','');

or try to write the hard code the Unique ID of Button1.
0
 

Author Comment

by:introlux
ID: 22613877
Error:

Compiler Error Message: CS0117: 'System.Web.UI.WebControls.Button' does not contain a definition for 'UniqueId'

Source Error:

 

Line 15: AC_FL_RunContent = 0;
Line 16:         function btnOkClick() {
Line 17:             __doPostBack(''<%=Button1.UniqueId%>'','');
Line 18:
Line 19:
 
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22613898
sorry for syntax, please use

Button1.UniqueID



or use the hard code unique id of Button1
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:introlux
ID: 22614000
It compiled but no output result!!
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22614056
do you mean you see the popup and when click on YES button, Button1_Click is not being executed ?

please check by using breakpoint.
0
 

Author Comment

by:introlux
ID: 22614161
Do I see prompt = Yes
When clicking on YES = It does not do anything

Does not hit breakpoint! (in code behind)
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 22614515
Hi,

You do realise I actually provided you with an answer on how to do this in your other question on the same subject: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23765696.html ?

In your case it's just a matter of:

a)
    <script language="javascript" type="text/javascript">
        function btnOkClick(sender, e) {
            __doPostBack(sender,e);
        }
    </script>

b)
        if (!Page.IsPostBack) {
            OkButton.OnClientClick = string.Format("btnOkClick('{0}','{1}')", OkButton.UniqueID, "MODALPOSTBACK");
        }

c)

        if (Page.IsPostBack) {
            string PostBackMode = Page.Request.Params["__EVENTARGUMENT"];
            if (string.Compare(PostBackMode, "MODALPOSTBACK") == 0) {
                        updateData();
                        sendMail2();
                        hardCopy();
                        excelFile();
                        DelLockSession();
            }
        }

/Carl.
0
 

Author Comment

by:introlux
ID: 22614748
I have done both possible solutions and niether of them work!

The normal process is not working now. Also the popup box appears but when clicking yes nothing happens!
0
 
LVL 7

Expert Comment

by:ajolly
ID: 22614832
You have written code in

btnOkClick() {


but your OnOkScript is "onOk()"

should you write:

function onOk()
{
    __doPostBack('<%=Button1.UniqueID%>','');
}
0
 
LVL 7

Accepted Solution

by:
ajolly earned 500 total points
ID: 22614853
and use one single quote '<%=Button1.UniqueID%>' .

In your code you have used 2 single quotes
0
 

Author Closing Comment

by:introlux
ID: 31501896
I Cannot believe it was sommet minor like that!

Thanks
0
 

Author Comment

by:introlux
ID: 22623110
Just wanted to add, that this check works all good. BUT when the user clicks on another option:

opProStatusDrop.SelectedValue == ???? (to something else)

Due to the popup modal being executed, it will not allow the user re-select a differ option and allow them to bypass this.

Any idea??

Regards,

introlux
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question