473,378 Members | 1,617 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,378 software developers and data experts.

Javascript In Codebehind

Hi,

I am new to javascripts..
i would like to write a javascript in .cs file and call it onLoad of a file.
Could you please let me know how to write a javascript in .cs file
Aug 26 '07 #1
5 2155
kenobewan
4,871 Expert 4TB
Welcome to TSDN. Have you tried using attributes.add?
Aug 26 '07 #2
phvfl
173 Expert 100+
Hi,

Javascript is a client side script. If you want a javascript function to execute once the page has loaded on the client add the function to the onload attribute of the body tag:

[HTML]
<body onload="jsFunction();">
[/HTML]

This would execute the function call jsFunction once the page has loaded.

If you are trying to add javascript to the aspx page during the page load event on the server then you would be using C# to generate the javascript and you could add it to a placeholder or literal control.
Aug 26 '07 #3
Hi,

I am new to javascripts..
i would like to write a javascript in .cs file and call it onLoad of a file.
Could you please let me know how to write a javascript in .cs file
In .CS file if u want to use javascript fuction u need working with a method
"RegisterStartupScript" ,using this method u can play with Javascript in codebehid file
Aug 26 '07 #4
onload i get a hidden field value. i have to check if the value is true then i have to submit the page. ie i want to do
document.forms[0].submit().

i want to know how i can write this script in .cs file assigning the javascript to a string and then using
Page.ClientScript.RegisterClientScriptBlock()


Hi,

Javascript is a client side script. If you want a javascript function to execute once the page has loaded on the client add the function to the onload attribute of the body tag:

[HTML]
<body onload="jsFunction();">
[/HTML]

This would execute the function call jsFunction once the page has loaded.

If you are trying to add javascript to the aspx page during the page load event on the server then you would be using C# to generate the javascript and you could add it to a placeholder or literal control.
Aug 26 '07 #5
string jsForControl = "document.getElementById('" + _hiddenId + "')";

string jsForAutoSubmit = "<script language='JavaScript'>function _autoSubmitPage(){var hdnTargetId="
+ jsForControl
+ ";if(hdnTargetId && hdnTargetId.value != ''){var hdnViewReportValue = ' + document.getElementById('" + _hiddenId + "').value + '; if (hdnViewReportValue == 'true'){' + document.forms[0].submit() + ';}}</script>";

Page.ClientScript.RegisterClientScriptBlock(this.G etType(), "autoSubmit", jsForAutoSubmit);

i am doing it this way can anyone plz let me know where i am wrong?
Aug 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Prescott | last post by:
I want to execute a javascript function that will set a value in the parent window from the child widow where its called and then post the form to the server. I seem to be able to execute one or...
3
by: nazim | last post by:
Hi, As a real novice trying to get to grips with c#.NET and html. I have created a simple showdialogbox which is called from within a webpage.aspx, I pass values to it from the main page and i...
5
by: Allan M. | last post by:
I have a series of select boxes that must be populated client side, because they interact with each other. The design specification calls for these boxes to be updated without having to make a...
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
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
2
by: Ekken Zuiber | last post by:
hiye people, i know this have been ask multipletimes over the past year, but i cant find any here in the new group so here goes.. in my code behind, i'm going to do some validation and use...
4
by: Rob Shorney | last post by:
Hi, I am using .Net 2003 , c# asp.net. The situation i have is this. I have a asp.net page which in the codebehind maintains an xml document in memory. The user can click on a button to popup a...
1
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
4
by: =?Utf-8?B?UmljaGFyZA==?= | last post by:
Hi, I have an ASP .NET page with codebehind in a vb file. The page has a dropdown control, and a JS function which used HTTP XML Request to get the data from the database, and populate the...
4
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.