473,699 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inject JavaScript from code behind

Hi,

I have a page which shows a matrix of names and grades for given period. All
the grades fields must be editable and
they can be up to 200 fields (20 students with 10 grades each)
Since there are a lots of fields I do not want to go back and forth to
validate entered values on any change.
I decided that this may be achieved with some JavaScript functions to
validate some controls and to calculate average and total values of other
controls on change of any editable fields.
On change value of input fields JavaScript function will check if this is a
valid value an if so it will calculate values of average and total fields
and update their values.
I use Textbox web control, I also add Attribute("onCh ange","return
validate(string id) ) to control to make it call proper JavaScript
function.

The valid grades are loaded from Database and need to be injected at run
time in the client html.
My problem is that I do not know how to inject(insert) this values as an
array in the client html so my function will use this values to validate the
user entry;

Thanks
Angel
Nov 18 '05 #1
3 12871
use StringBuilder to builder a string which will represent a
<script language=javasc ript>
// your javascript array definition here
</script>

StringBuilder sb = new StringBuilder() ;
sb.Appent("<scr ipt language=javasc ript>\n");
sb.Append(" var myArray[5];\n")
sb.Append("myAr ray[0] = " + serversideArray _or_list[0] + "\n");
// add more array items or use a for loop etc.
sb.Appent("</script>\n");
Page.RegisterCl ientsideScript( "yourscriptrefe rence", sb.ToString());

something like this

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Angel" <an*****@hotmai l.com> wrote in message
news:OF******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I have a page which shows a matrix of names and grades for given period. All the grades fields must be editable and
they can be up to 200 fields (20 students with 10 grades each)
Since there are a lots of fields I do not want to go back and forth to
validate entered values on any change.
I decided that this may be achieved with some JavaScript functions to
validate some controls and to calculate average and total values of other
controls on change of any editable fields.
On change value of input fields JavaScript function will check if this is a valid value an if so it will calculate values of average and total fields
and update their values.
I use Textbox web control, I also add Attribute("onCh ange","return
validate(string id) ) to control to make it call proper JavaScript
function.

The valid grades are loaded from Database and need to be injected at run
time in the client html.
My problem is that I do not know how to inject(insert) this values as an
array in the client html so my function will use this values to validate the user entry;

Thanks
Angel

Nov 18 '05 #2
Or you could use the Page.RegisterAr rayDeclaration

something like Page.RegisterAr rayDeclaration( "myArray", "1,2,3,4,5,6,7" );

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:O7******** ******@TK2MSFTN GP11.phx.gbl...
use StringBuilder to builder a string which will represent a
<script language=javasc ript>
// your javascript array definition here
</script>

StringBuilder sb = new StringBuilder() ;
sb.Appent("<scr ipt language=javasc ript>\n");
sb.Append(" var myArray[5];\n")
sb.Append("myAr ray[0] = " + serversideArray _or_list[0] + "\n");
// add more array items or use a for loop etc.
sb.Appent("</script>\n");
Page.RegisterCl ientsideScript( "yourscriptrefe rence", sb.ToString());

something like this

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Angel" <an*****@hotmai l.com> wrote in message
news:OF******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I have a page which shows a matrix of names and grades for given period. All
the grades fields must be editable and
they can be up to 200 fields (20 students with 10 grades each)
Since there are a lots of fields I do not want to go back and forth to
validate entered values on any change.
I decided that this may be achieved with some JavaScript functions to
validate some controls and to calculate average and total values of other controls on change of any editable fields.
On change value of input fields JavaScript function will check if this is a
valid value an if so it will calculate values of average and total

fields and update their values.
I use Textbox web control, I also add Attribute("onCh ange","return
validate(string id) ) to control to make it call proper JavaScript
function.

The valid grades are loaded from Database and need to be injected at run time in the client html.
My problem is that I do not know how to inject(insert) this values as an
array in the client html so my function will use this values to validate

the
user entry;

Thanks
Angel


Nov 18 '05 #3
oh... never had to use one.. hmmm keep that in mind next time :)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2******** ******@TK2MSFTN GP10.phx.gbl...
Or you could use the Page.RegisterAr rayDeclaration

something like Page.RegisterAr rayDeclaration( "myArray", "1,2,3,4,5,6,7" );

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:O7******** ******@TK2MSFTN GP11.phx.gbl...
use StringBuilder to builder a string which will represent a
<script language=javasc ript>
// your javascript array definition here
</script>

StringBuilder sb = new StringBuilder() ;
sb.Appent("<scr ipt language=javasc ript>\n");
sb.Append(" var myArray[5];\n")
sb.Append("myAr ray[0] = " + serversideArray _or_list[0] + "\n");
// add more array items or use a for loop etc.
sb.Appent("</script>\n");
Page.RegisterCl ientsideScript( "yourscriptrefe rence", sb.ToString());

something like this

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Angel" <an*****@hotmai l.com> wrote in message
news:OF******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I have a page which shows a matrix of names and grades for given period.
All
the grades fields must be editable and
they can be up to 200 fields (20 students with 10 grades each)
Since there are a lots of fields I do not want to go back and forth to
validate entered values on any change.
I decided that this may be achieved with some JavaScript functions to
validate some controls and to calculate average and total values of other controls on change of any editable fields.
On change value of input fields JavaScript function will check if this is
a
valid value an if so it will calculate values of average and total fields and update their values.
I use Textbox web control, I also add Attribute("onCh ange","return
validate(string id) ) to control to make it call proper JavaScript
function.

The valid grades are loaded from Database and need to be injected at run time in the client html.
My problem is that I do not know how to inject(insert) this values as

an array in the client html so my function will use this values to

validate the
user entry;

Thanks
Angel



Nov 18 '05 #4

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

Similar topics

0
1752
by: Fabien Penso | last post by:
Hi. I am looking for the proper way to fetch a webpage, inject javascript and run an IE component on it. I've been looking around with no luck. For now I thought about: 1. fetch the webpage with a webrequest 2. make modifications (I would prefer to have access to the DOM) 3. run an IE component on the new source
5
14745
by: Vinod Kumar | last post by:
Hi All, Can I access a Javascript function written in an ASP.NET from the codebehind (C#) of that page? If yes, kindly give the code snippet to do this. Thanks and Regards Vinod Kumar
4
1977
by: Nevyn Twyll | last post by:
I have a web form, with c# code-behind. I have a listbox on the form, bound to a dataset. I want to have 2 buttons/hyperlinks/etc. beside the listbox. When they are clicked, I want to launch a popup form, passing it some information from the listbox (record id) and the linked information. If I could show the data in place of the page showing, I know how to get the data and use Response.Redirect(). Since it needs to be a popup, I know...
1
9128
by: Machi | last post by:
let say i have a web form with a button on it ... when i click the button, it will pop up one small window to allow me to save a pdf file, everything is done using code behind as below ... however, in javascript, i have set a global variable as a flag to indicate the number of times user click the buttion (let say flagNoOfClick), when user clicks the button once, it will set the flag (flagNoOfClick) to "true" (by using javascript). So, when user...
1
1471
by: sklett | last post by:
I want to implement a simple form element focus script that will change the color of a form element when it gets focus and revert back when it loses focus. I've got the code working (simple) but now I need to add it to ALL my form controls and there are tons. Is there a way to override page rendering and insert the javascript into the rendered page source? For example, this is what I would like to add to my controls:...
2
1592
by: ChrisA | last post by:
Is there a way to inject a large javascript function into an asp.net page, in 1.1 and 2.0?
2
4909
by: Kris | last post by:
Problem with getting data out of injected script template.html contains the following html and is located at http://example.com/template.html: <html> <head> <title></title> </head> <body>
5
1990
by: mesut | last post by:
Hi there, how are you colleagues? I try to set a linkaddress in code behind for a <asp:hyperlinkserver control. but I think I have some syntax problem. I don't know how to fix it. What's wrong with the code below? I have put a hyperlink on the aspx page. And I add the attributes of the hyperlink in my code-behind. I set the attributes in code behind because I need the AddressGuid ID value. I concattenate the value and make an URL...
1
3489
by: =?Utf-8?B?SkhpbGJDUk0=?= | last post by:
I am trying to write a httpmodule to inject javascript includes on some of the aspx pages we have. For instance, I want to inject into the resulting IIS response something like... response.Write("<script language='javascript'>"); response.Write("alert('tt');"); response.Write(@"</script>");
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
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...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
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
7755
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...
1
6536
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4378
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...
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.