Click here to Skip to main content
15,891,423 members

Calling javascript function from code behind

freefika asked:

Open original thread
I have an account settings page where the user can change the company name, admin password or main password. I am using javascript and links. When user click the "change admin password" link, the javascript code is called and the appropriate "div" is set to style.display=inline (otherwise its always style.display=none). After setting the password, the user clicks "Save Password" (a button). This causes a postback and so the visible "div" gets hidden.

I am trying to call a javascript function on page_load to check if the user was working on the admin password, it should display it i.e set style.display=inline... however i am unable to do that. The code i am using just gets called ONCE but not on every postback. Kindly help:

Here is my code for calling the javascript function on page_load


VB
If (Not ClientScript.IsStartupScriptRegistered("viewdiv")) Then

                Page.ClientScript.RegisterStartupScript _
(Me.GetType(), "viewdiv";, "view('divAdminPassword');", True)
            End If


And my javascript function is:

C#
function view(obj)
     {
         var div = document.getElementById(obj);


                div.style.display = "inline";

    }
Tags: Visual Basic, Javascript, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900