?
Solved

Call Javascript from Server side

Posted on 2007-11-19
5
Medium Priority
?
1,546 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 1500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

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