Solved

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

Posted on 2010-11-27
5
838 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp day pilot 3 19
EF5: Question about Metadata Artifact Processing 4 15
C# Desktop Application 3 32
Client Validating 2 date fields, required & comparison 1 24
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 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