473,748 Members | 7,571 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 12875
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
14746
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
1983
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
9130
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
1473
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
4910
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
1991
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
3490
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
8830
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
9544
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
9372
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
9324
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
6074
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
4606
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.