Solved

Call Javascript from Server side

Posted on 2007-11-19
5
1,543 Views
Last Modified: 2012-08-14
Greetings

Noit to long ago "CodeClay" very kindly helped me with some JavaScripting and explained how the ASP.Net code executes on Server side, while the JavaSCript does it's thing on Client side (I hope that I've said thgis correctly). That explain why in a procedure with several lines of code, followed by JS call, I never saw the JS (in this a messagebox) executed - you'd have to move the JS to Server-side (again, I hoep thatI'm saying this correctly!).

I now have a need for such an event - where after an insertion I want to display a message.

WHAT CAN I DO TO GET THIS TO WORK ?

My Code:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // Set up event handlers for local buttons.
            btnLocalInsert = (Button)this.Master.FindControl("btnInsert");
            btnLocalInsert.Click += new EventHandler(btnLocalInsert_Click);
        }
    }

    protected void btnLocalInsert_Click(object sender, EventArgs e)
    {
       ..............................................
       ........................................
       ......................................................
       .....................................
        Alert.Show("Your password will be emailed to you!");       // Alert is a simple class that contains
    }                                                                                                // teh code for the JS scripting

0
Comment
Question by:allanmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:allanmark
ID: 20317716
Sorry ...

Just had another thought, re-lloking at my code.The lines below - coudl they not be placed under the
PageInit?

            btnLocalInsert = (Button)this.Master.FindControl("btnInsert");
            btnLocalInsert.Click += new EventHandler(btnLocalInsert_Click);
0
 
LVL 5

Expert Comment

by:gocemi
ID: 20318096
Hi,

Thing is frend that you can register javascript from the server side to be executed on a client side.
This is done trough Page.RegisterClientScriptBlock("id of the script","<script>alert('here content')</script>");
After page is finished loading, on render will put this script in the document so it'll be executed as soon as document is loaded.

Personally, i would recommend for you to use label with same text and hide/ show depending on whether button is clicked on not.

But anyway Page.RegisterClientScriptBlock will do your job.

Br,
0
 
LVL 9

Expert Comment

by:codeclay
ID: 20318663
Hello Allan,

Your code will work fine .If its the last statement in the btnLocalInsert_Click event .

Thanks.
Aby.
0
 

Author Comment

by:allanmark
ID: 20322340
Thanks, both of you for the speedy replies.

I fiddled around and guess what was giving me the ehadache ....

   if (!Page.IsPostBack)  .....  I REMOVED THIS AND IT WORKS!!!!

Once again, I'm going to eb really cheeky and slip anothe rquestion in, but coiuld you point me in the direction of some decent literature regarding POSTBACK and PAGES  ... quite obvious that I need some :(  :(.
0
 
LVL 9

Accepted Solution

by:
codeclay earned 375 total points
ID: 20325786
Here is acloser look at the POstBack feature in ASP.Net http://www.xefteri.com/articles/show.cfm?id=18
And this will be a good place to start learning ASP.NET .
http://www.asp.net
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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