Solved

Calling the ASP.NET server side event handler from the jquery client side function

Posted on 2010-11-27
5
836 Views
Last Modified: 2012-05-10
I have a server asp.net Button "btnSendmail".
Its server side  "On Click" event handler is "btnSendEmail_Click" ,and the client side function
on "OnClientClick" is "hideModal".

This button is on the AJAX modal pop up extender, I want that send eemail functionality of server side event handler executes first, and after I can call the client side script "OnClientClick" to close the modal dialog.
I have been trying this:
 function hideModal() {
          $find('mpUserNotificationBehavior').hide();
      }

It sems that its been cl,osing the Modal dialog without executing the server side event handler functionality..
How should I proceed in this situation.
The requirement is that I have to close the modal dialog once the server side is executed successfully.

Urgently required
0
Comment
Question by:Ammar Iqbal
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34222311
The OnClientClick will always execute first, so I suggest you remove it and add a script to be executed after your btnSendEmail_Click is fired.  Add a ScriptManager to your page and then your btnSendEmail_Click event should look like this :

protected void btnSendEmail_Click(object sender, EventArgs e) {
    // send your email
    ScriptManager.RegisterStartupScript(Page, this.GetType(), "ClosePopup", "<script>$find('mpUserNotificationBehavior').hide();</script>", false);
}

Hope it helps,

Burnie
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 34222357
Do I need to write this Script Manager code  after my server side code?
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 34222450
I am also invoking the Details View item inserting event in this btn Send email  event handler, IT has been invoked .,it is calling the insert event handler. but the record is not inserted ,and straight way  after this ,the script manager is executed.

One more question, Why the first parameter of script manger register script is "Page".Is it pointing to the page .or the modal pop up dialog
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34222459
Yes, you need to write this script manager code at the end of your server side code.

The first parameter Page will point to the Page.

Are you rebinding your details view after inserting the record?
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 34222469
yes of ocurse, the  main point is that my button  is within the Panel of the modal pop extender, and here the record is not inserted.
IF i place this button outside the panel, and that Details view is inserting a new record succesfully
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now