473,811 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling javascript from C#--help please

// I wrote the following code but it is not working.
// Any help please?
// ------------------------------------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace Testings
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class CallJavaScriptF romServerCode : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
string toRed = "<script language=\"java script\"> ";
toRed += "function RedIt() { ";
toRed += "document.bgCol or = \"red\"; } ";
toRed += "</script>";

if(!IsClientScr iptBlockRegiste red("bgColor"))
{
RegisterClientS criptBlock("bgC olor",toRed);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}
Nov 19 '05
10 1591
Bruce Barker:
You just wrote what I did write.

S.Justin Gengo:
1- I know that javascript is a client side code, I want to run that client
side code with server side controls.
2- The first code you wrote actually did it
3- I would greatly appreciate you if you write to me a server side code that
can change the background color on click of a button
4- In the second code you wrote, you should write the javascript code in the
..aspx page not the .aspx.cs page so it doesn't work

Sreejith Ram:
1- Your code also worked
2- Thank you for the reading source

The conclusion:
the keyword function ****()
should only be written when you will call it later by onclick="****() ;" in
the inline code page
"Sreejith Ram" <Sr*********@di scussions.micro soft.com> wrote in message
news:ED******** *************** ***********@mic rosoft.com...

A little bit of reading on Client Side scripting with ASP may help

http://www.c-sharpcorner.com/Code/20...eScripting.asp

"Bishoy George" wrote:
// I wrote the following code but it is not working.
// Any help please?
// ------------------------------------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace Testings
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class CallJavaScriptF romServerCode : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
string toRed = "<script language=\"java script\"> ";
toRed += "function RedIt() { ";
toRed += "document.bgCol or = \"red\"; } ";
toRed += "</script>";

if(!IsClientScr iptBlockRegiste red("bgColor"))
{
RegisterClientS criptBlock("bgC olor",toRed);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}

Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5194
by: StealthMonkey | last post by:
Let me prefix this by saying that I know next to nothing about Java (so please try to keep explainations simple). I use PHP for my server-side web programming. Here is my dilemma: I need a JavaScript function to be called with a dynamic parameter, an ID# known by the server. The way I would go about doing this in PHP would be extremely simple: <script> foo(<?PHP echo ID; ?>);
1
1674
by: questionr | last post by:
There is a spell checker function which is written in VB Script. The function works well when tested seperately. But when the function is called from Java Script, the function shows an Error saying " A run time error has occured. Do you wish to debug? Line :0 , Object Expected". I just know that it is a Java Script error. Any suggestions on how to resolve this problem ? What could be the possible reasons for this error message?
5
51483
by: Krishna | last post by:
Hi all, Can i call my javascript functions from the web controls.Any appropriate site which will be tell more on this will be helpfull. Regards.., Krishna
6
751
by: szabelin | last post by:
Hello, I am trying to call a function inside the javascript block from asp.net during the postback (NOT button's OnClick event handler though). The javascript function creates new popup window. I register the javascript code with the RegisterClientScriptBlock. How how do I call the javascript function inside the block from within C# asp.net page. (yes I know popups are bad, please do not reply if you
4
6341
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB Code: Public Sub VBProcedure() .. ..
5
1721
by: srini.venkatesan | last post by:
I am trying to call a javascript from Datagrid which is using OnUpdatecommand, I dont see update being invoked, what am I missing, Is it the right way to call. I have just cut and pasted only the part of the code. Thanks In the class file: public void DataGrid2_Edit(Object sender, DataGridCommandEventArgs e) { DataGrid2.EditItemIndex = (int)e.Item.ItemIndex; BindGrid();
0
1253
by: cs2007 | last post by:
Hi, My question on custom webpart creation in c#. One quick question, can you please tell me the syntax or step to call the java script from Output.write(<a href=.....) SCENARIO: click here should act as a link. And the link should invoke javascript. for eg: output.Write("<a href="#"" onclick="javascript:validateSubmit();" ">" Click here "</a>"); Here Im getting following errors on compilation 1. "Preprocessor directives must appear...
1
2006
by: neerom | last post by:
Hi I need to call webservice from xslt in HTTP POST Method. The MSXML should be used. I am using javascript. I have an XML File which is having Integer Node.....Shown Below <?xml version="1.0" encoding="utf-8" ?> <NumberSet> <integer> <a>10</a> <b>12</b>
0
10652
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10408
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6895
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5561
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.