Solved

ModalPopupExtender raising even when user hit the OK button

Posted on 2008-10-23
6
596 Views
Last Modified: 2011-09-20
Just starting with Ajax .NET and i can't find how to call a server codebehind even "C#", when the user hit the "OkControlID" button.

Any other solution than setting a "OnOkScript" javascript and submiting a form?
Is it possible to simply tell the popup to call a server side event when the user hit the "OK" button?

Thanks!!
0
Comment
Question by:jabcoco
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22793466
There is good explanation on what AJAX is at
http://en.wikipedia.org/wiki/Ajax_%28programming%29
http://www.skeymedia.com/programming/classic-asp-and-ajax-tutorial/
The reference site W3Schools has a good section on AJAX at http://www.w3schools.com/ajax/default.asp
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22794278
Hi

What I do is, I create a hidden field and set the TargetControlID to that field, the Ok button has it own Click event (which call server side function) and programatically show the ModalPopup, because I need to set values for that PopUp window, so this comes very handy.

 public void LoadMPENewObject()
    {
       //Load new object data depend on pre user input:
       LoadNewObjectPredefined();

       //show the modal popup
        mpe.Show();          
    }


YOu can do the same thing, and even create the modal popup dynamically (look at my code)
(just incase you need reference)

JINN

 public void LoadMPENewObject()
    {
        ModalPopupExtender mpe = new ModalPopupExtender();
        mpe.PopupControlID = pnAddNewObjectPopup.ID;
        mpe.TargetControlID = btAddNew.ID;
        mpe.PopupDragHandleControlID = pnNewObjectCaption.ID;
        mpe.BackgroundCssClass = "modalBackground";
        plhNewobjectMPE.Controls.Add(mpe);
        mpe.Show();
          
    }

Open in new window

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22794288
And this is the nomarl Button_Click event which load the previous code:

 protected void btAddNew_Click(object sender, EventArgs e)
    {
       //clear the new object popup values
        ucNewObject.ClearForm();

        //Load predata and show popup
        LoadMPENewObject();
    }

JINN
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 10

Accepted Solution

by:
jabcoco earned 0 total points
ID: 22808516
jinn_hnnl, what i was looking for is "executing" code behind C# when user hits the "Ok" button inside the modal popup, not showing a modal popup from code behind

Here is the solution i"m looking for

Thanks for your effort! :)
page.aspx
----------------------
<asp:Panel runat="server" ID="panContent" CssClass="ajax_ModalPopup" Style="display: none">
  <asp:UpdatePanel ID="updtPanelModalPopup" runat="server">
    <ContentTemplate>
      Login:<asp:TextBox ID="txtUser" runat="server"></asp:TextBox><br />
      Pass:<asp:TextBox ID="txtPass" runat="server"></asp:TextBox><br />
      <asp:Button ID="btnOk" runat="server" Text="LogOn" />
    </ContentTemplate>
  </asp:UpdatePanel>
</asp:Panel>
 
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupCtrl"
    PopupControlID="panContent" 
    CancelControlID="btnClose"
    BackgroundCssClass="ajax_ModalPopupBackground"/>
 
page.aspx.cs
----------------------
void btnOk_Click(object sender, EventArgs e){
   ...//add your server side code and use modalPopupCtrl.hide() to close popup. and updtPanelModalPopup.Update();}

Open in new window

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22809014
Hi, sorry for late response.

Have you solved your problem? If you want to execute on any Button click as that button click is inside the ModalPopup, then just do it normally, set the OnClick event equals btnOk_Click, just like any another server button.

Incase you dont see anychanges was made, and actually the button was fired, page was posted back to server, but because you have that ok button inside the UpdatePanel, that's why only partly of the page/the updatePanel was updated. In that case, try to allocate the OkButton outside the updatePanel

Hope this help

JINN
0
 
LVL 10

Author Comment

by:jabcoco
ID: 22809093
jinn_hnnl, thanks! But has you can see i've solve my problem with the current question.

But i still have a other problem, maybe you can help on this ajax subject.
Please refer to : http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23849113.html

thanks :)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP - AJAX and MySQL it works only if the value is a number 12 55
Web site error 3 40
encoding an href string 2 20
PHP AJAX JSON 2 59
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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