Solved

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

Posted on 2010-11-27
5
832 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
Comment Utility
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
Comment Utility
Do I need to write this Script Manager code  after my server side code?
0
 
LVL 1

Author Comment

by:Ammar Iqbal
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to go to Web page 2 46
Exception in Log4Net 1 17
Set cookies HttpOnly and Secure 4 50
Problem to open Excel file 15 37
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

11 Experts available now in Live!

Get 1:1 Help Now