Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Calling a javascript function from server script URGENT HELP

Reply
Thread Tools

Calling a javascript function from server script URGENT HELP

 
 
Silvia Brunet Jones
Guest
Posts: n/a
 
      07-28-2003
Ok I am about to pull my hair.
I have an active x control in an object tag which, as you
know cant have runat=server. So what I need is to not
loose what is in this box everytime a postback happens. So
all I want to do is add this statement
document.all.txtEditor.value =
document.all.Transcription.objEditor.textrtf;
in the before the page is posted so that I can then
retrive it and put it back.
WHY CANT I DO THIS!!!!!!!!!!!!
I have tried all kinds of things, the submit function is
not getting called when the postback occurs.
There has to be a way how to call a javascript function
from the server side code. Where I can put this in the
private void Page_Unload(object sender, System.EventArgs e)
at least.
HELP
 
Reply With Quote
 
 
 
 
Alexander
Guest
Posts: n/a
 
      07-29-2003
It is impossible to call javascript function from server script.
Your JavaScript code has to be called on client side just before
postback to server.
There is a simple trick to add your JavaScript client side code to
submit button.
On the server side you should to write something similar (I prefer C#,
you will make the same basic.net code):

this.btnSave.Attributes.Add("onclick", "document.all.txtEditor.value =
document.all.Transcription.objEditor.textrtf;");
this.btnSave.Attributes.Add("language", "javascript");

The problem with this javascript code execution is possible if you
have Visual Studio standard validators on the page.
If you have validators the trick is more complex and has two steps:
a) you have to set the submit button property "CausesValidation" to
false;
b) just after your JavaScript code you have to add: if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
as a result your code should be:
this.btnSave.Attributes.Add("onclick", "document.all.txtEditor.value =
document.all.Transcription.objEditor.textrtf; if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate();");

I use the similar code on the site
http://alnet.europe.webmatrixhosting.net/ on Make Your Puzzle page. It
works.

Best Wishes,
Alexander
http://www.velocityreviews.com/forums/(E-Mail Removed)

"Silvia Brunet Jones" <(E-Mail Removed)> wrote in message news:<03e501c35552$c51d8030$(E-Mail Removed)>...
> Ok I am about to pull my hair.
> I have an active x control in an object tag which, as you
> know cant have runat=server. So what I need is to not
> loose what is in this box everytime a postback happens. So
> all I want to do is add this statement
> document.all.txtEditor.value =
> document.all.Transcription.objEditor.textrtf;
> in the before the page is posted so that I can then
> retrive it and put it back.
> WHY CANT I DO THIS!!!!!!!!!!!!
> I have tried all kinds of things, the submit function is
> not getting called when the postback occurs.
> There has to be a way how to call a javascript function
> from the server side code. Where I can put this in the
> private void Page_Unload(object sender, System.EventArgs e)
> at least.
> HELP

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
Calling a javascript function from server script URGENT HELP Silvia Brunet-Jones ASP .Net 1 07-28-2003 10:46 PM
Calling a javascript function from server script URGENT HELP Silvia Brunet Jones ASP .Net 0 07-28-2003 10:02 PM



Advertisments