[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1445
  • Last Modified:

ModalPopupExtender execute code behind event HELP!

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
introlux
Asked:
introlux
  • 6
  • 5
1 Solution
 
ajollyCommented:
in javascript function onOk()

write following:

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

or try to write the hard code the Unique ID of Button1.
0
 
introluxAuthor Commented:
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
 
ajollyCommented:
sorry for syntax, please use

Button1.UniqueID



or use the hard code unique id of Button1
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
introluxAuthor Commented:
It compiled but no output result!!
0
 
ajollyCommented:
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
 
introluxAuthor Commented:
Do I see prompt = Yes
When clicking on YES = It does not do anything

Does not hit breakpoint! (in code behind)
0
 
carlnorrbomCommented:
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
 
introluxAuthor Commented:
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
 
ajollyCommented:
You have written code in

btnOkClick() {


but your OnOkScript is "onOk()"

should you write:

function onOk()
{
    __doPostBack('<%=Button1.UniqueID%>','');
}
0
 
ajollyCommented:
and use one single quote '<%=Button1.UniqueID%>' .

In your code you have used 2 single quotes
0
 
introluxAuthor Commented:
I Cannot believe it was sommet minor like that!

Thanks
0
 
introluxAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now