473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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("onChange","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 12856
use StringBuilder to builder a string which will represent a
<script language=javascript>
// your javascript array definition here
</script>

StringBuilder sb = new StringBuilder();
sb.Appent("<script language=javascript>\n");
sb.Append(" var myArray[5];\n")
sb.Append("myArray[0] = " + serversideArray_or_list[0] + "\n");
// add more array items or use a for loop etc.
sb.Appent("</script>\n");
Page.RegisterClientsideScript("yourscriptreference ", sb.ToString());

something like this

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Angel" <an*****@hotmail.com> wrote in message
news:OF**************@TK2MSFTNGP09.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("onChange","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.RegisterArrayDeclaration

something like Page.RegisterArrayDeclaration("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**************@TK2MSFTNGP11.phx.gbl...
use StringBuilder to builder a string which will represent a
<script language=javascript>
// your javascript array definition here
</script>

StringBuilder sb = new StringBuilder();
sb.Appent("<script language=javascript>\n");
sb.Append(" var myArray[5];\n")
sb.Append("myArray[0] = " + serversideArray_or_list[0] + "\n");
// add more array items or use a for loop etc.
sb.Appent("</script>\n");
Page.RegisterClientsideScript("yourscriptreference ", sb.ToString());

something like this

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Angel" <an*****@hotmail.com> wrote in message
news:OF**************@TK2MSFTNGP09.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("onChange","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**************@TK2MSFTNGP10.phx.gbl...
Or you could use the Page.RegisterArrayDeclaration

something like Page.RegisterArrayDeclaration("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**************@TK2MSFTNGP11.phx.gbl...
use StringBuilder to builder a string which will represent a
<script language=javascript>
// your javascript array definition here
</script>

StringBuilder sb = new StringBuilder();
sb.Appent("<script language=javascript>\n");
sb.Append(" var myArray[5];\n")
sb.Append("myArray[0] = " + serversideArray_or_list[0] + "\n");
// add more array items or use a for loop etc.
sb.Appent("</script>\n");
Page.RegisterClientsideScript("yourscriptreference ", sb.ToString());

something like this

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Angel" <an*****@hotmail.com> wrote in message
news:OF**************@TK2MSFTNGP09.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("onChange","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
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...
5
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
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...
1
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,...
1
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...
2
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
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
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...
1
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... ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.