calling a javascript function from a c# function

I'm using, c# framwork 1.1 and some javascript.

I have a table in which there are 3 cells.
In each cell there is a control.
In the first cell the control ID is DropDownList1 and the items are Item1, Item2 and Item3.
In the second cell, the control ID is TextBox2.
In the third cell, the control ID is TextBox3.

What i am trying to do is :
If DropDownList1 selected value equal Item1
   then hide the second AND the third cells.
If DropDownList1 selected value equal Item2
   then show the second cell AND hide the third cell.
If DropDownList1 selected value equal Item3
   then hide the second cell AND show the third cell.

I am using javascript to do so because when i hide a cell, i want all the other cells of the table shift and take place of the hidden one.

So here is what i did :

Between the head tag :
function makeVisibleInitCells_()
   var Statut = document.all['DropDownList1'];
   var Cell2 = document.all['IDCell2'];
   var Cell3 = document.all['IDCell3'];

   if(Statut.options[Statut.selectedIndex].value == "Item1")

   if(Statut.options[Statut.selectedIndex].value == "Item2")
   if(Statut.options[Statut.selectedIndex].value == "Item3")

Between the script tag :
void makeVisibleInitCells(object sender, EventArgs e)

Between the body :
         <asp:DropDownList id="DropDownList1" runat="server" OnSelectedIndexChanged="makeVisibleInitCells">
            <asp:ListItem Value="Item1">Item1</asp:ListItem>
            <asp:ListItem Value="Item2">Item1</asp:ListItem>
            <asp:ListItem Value="Item3">Item1</asp:ListItem>
      <td id="Cell2">
            <asp:textBox id="TextBox1" runat="server" ></asp:TextBox>
      <td id="Cell3">
            <asp:textBox id="TextBox2" runat="server" ></asp:TextBox>

But this doesn't work not even an "error in the page" error at the bottom of my IE...
Can you help me ?

Amat Victoria Curam
7/7/2005 10:33:01 AM 24353 articles. 2 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 38

get rid of OnSelectedIndexChanged="makeVisibleInitCells"> set autopost back to false

on the page load of the code behind add this




make it


for the cells

Eric | Twitter epascarello | LinkedIn
7/7/2005 11:37:56 AM

Ok this part works fine now, thanks to you :)

An other issue :
I want Cell2 and Cell3 hidden or visible, depending the selected value of DropDownlList1 when the page loads itself.
I have tried these two things but nothing happens :
DropDownList_Statut.Attributes.Add("onLoad", "makeVisibleInitCells_();");
Form1.Attributes.Add("onLoad", "makeVisibleInitCells_();");

Something else i have tried which almost works is this :
Form1.Attributes.Add("onClick", "makeVisibleInitCells_();");

It works because actually the table containing Cell1, Cell2 and Cell3 is hidden when the page load itself. So this table appears when the user clics on another existing table. But then when i fill in either Cell2 or Cell3 TextBox and then clic somewhere else on the page, the TextBox are re-initialized.

How can i make these cells properly shown up when the page load and then abbled to fill them in ?

Amat Victoria Curam
7/7/2005 4:07:25 PM
You can add the onload function call to the body tag.

Eric | Twitter epascarello | LinkedIn
7/7/2005 4:43:46 PM
Awsome that's working !!

Thanks alot :)
Amat Victoria Curam
7/7/2005 5:20:11 PM

Similar Artilces:

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

Can you call a c# on the server side from javascript functions on client side
Hello guys This is something intresting I have come across during development. I have a javascript written in a .JS file , to my knowledge the .js files are executed on the server side. But security concerns with java script that these .js files can be access by connecting to port 80 of the server . So an ultimate alternative reminas to call c# code from a java script function. Can anyone Help me on this matter Regards Nihar Hi Nihar, Usually .js files executed on client side. Please explain your configuration.Leon LangleybenMCSD, ASP.NET MVPBlog...

Call c# function from javascript function
This is my code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <%@ Import Namespace="System.Web.Services" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head runat="server"> <title>Untitled Page</title> <script runat= server> [WebMethod] public string GetName() { return "Hello Word"; } </script> <script language=javascript type="text/javascript">...

calling c# function in javascript function
I'm trying to call a c# function in my javascript function that I use as a buttons OnClientClick. The c# function simply changes some session variable values. The problem I'm having is that everytime my page posts back the c# function that is called within my javascript function is executing, and the only time it should execute is when the button is pressed. I'm not sure what I'm doing wrong but heres my code: <script type="text/javascript"> function Go() { <%SetDefault(); %>'','mywindow4','scrollbars=yes,l...

Need help converting a C#/.NET method into client-side (javascript) function
Hey Guys, I have implemented an AJAX Toolkit CalendarExtender.  I have a method 'CheckDate' in javascript (followed a tut!) that checks to see if the user selected a date > DateTime.Now(). Well, I have a few other things to check but not sure how to do them in javascript, so I'm hoping someone here can help me.  I mean, i can somewhat convert it but it'll be too mangled, I'd rather learn the right way.  I'm attaching the code and any help will be appreciated.  1 protected string CheckDateErrors(string dateGiven) 2 ...

How to call server side function from client side JavaScript?
I want to call a server-side function, like a button's click event or just another private or public function , from a client-side JavaScript function. How do I do that? thanX AnzIf this post was useful to you, please mark it as answer.ClientSideAsp.Net | Blog Maybe alittle more that you need, but....... 1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false 2) Write the code for the button. 3) Write the following in the PAge_Load event Button1.Attributes.Add("onClick", "myJSFunction(); return false") 4) Copy this javascript...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, y...

how to call server side function from client side javascript?
Hi all, I have a image button in the update panel. I would like to call a method from server side (not from webservice) to get the variable when Onclick on the image button is invoked. Is there any way that I can able to access this function from the client script? In using the UpdatePanel, in essence, you're already doing this because there will not be a full postback.  You can make an asynchronous call to your Click method of your ImageButton.  So, what do you want to do with this "variable"?Christopher Reed"The oxen are slow, but the earth is patient."...

how to call server side function in javascript function
right now I have a question. I have a javascript function which created a textfield. what I want to do is when the user type in the value into the textfield, it will call the function in the server side and search the data in the database. I wonder is it possible to do that? And how to do it, can anyone some me some example..thx    look into ajax autocomplete Liming XuJumptree ASP.NET 2.0 Project Management - With Source Code, Free to Non Profit Org and Effectively Manage Projects/Tasks/Milestones Superwong-You definitely want to use Ajax (as was suggested). Since you're u...

call a server side function from javascript function
hello i have apage that is contained in MasterPage (contents) i have a HyperLink and i want to call a serverside function is it possible? i am writing C# nirnironIf i helped you please mark as answered.. in your page_load event, you can reference controls on the masterpage by MasterPage.FindControl("....")  Peter Kellner and blogging athttp://PeterKellner.netMVP, ASP.NET  Use the "LinkButton" control...  Looks the same as a hyperlink, acts the same, and you can catch events from it. no... ok this is the scenario... i have ...

How to call a javascript function from a server-side function
Hi. I'd like to know if it's possible to call a javascript function from within a server-side function. I know it's possible to associate a javascript function with a control event but I'd like to call it from within an function.  Thanks, Samir Zattar Hey, There are several ways to do it, all through the Page.ClientScript property.  You can write a script through RegisterClientScriptBlock or RegisterStartupScript, or if you have a script file you can write a reference to that file.Brian"Trust in the Lord and do what is good; dwell in the land and ...

calling server-side c# function in javascript
will you please help me on how to call a c# method in javascript. the known solution using adding an onclick event to a button and firing postback is not what i have to do. The problem is that i need to be able to call any function. Hi, you can also use the __doPostBack Javascript method on the client to call a serverside function. In the page_load event you can check which function is requested, e.g.:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Evaluator.aspx.cs" Inherits="Evaluator" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www....

want to call a function of from javascript
hi everyone. i want to call a function of from javascript. and i also want to pass an argument from javascript to  that function. can anyone help me? thanks in advance. shweta  ThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path Can you be more precise about the effect you're trying to achieve?  Explain you requirements , what you want to achieve be thisIf this post helps you, please mark it as Answer.Cheers,Muhammad Rizwan JavedSr .Net DeveloperAim 168, Dubai, UAE. Hi Try this, U'r Codeb...

How to javascript function from C# function ?
i have a popup function in the javascript. when ever i call it from HTML controls's onClick event it is working well. but when ever i writeResponse.Write("<script>"); Response.Write("PopupPicker(215,200);"); Response.Write("</script>"); in c# method it doesn't work any javascript function is as follow:<script language="javascript"> function PopupPicker(w,h) { var PopupWindow=null,settings; settings='width='+ w + ',height='+ h + ',location=no,directories=no,men...

Web resources about - calling a javascript function from a c# function -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 12/11/2015 9:05:04 AM