Click here to Skip to main content
12,406,687 members (58,441 online)
Rate this:
 
Please Sign up or sign in to vote.
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


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

And my javascript function is:

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

                div.style.display = "inline";
 
    }
Posted 15-Sep-10 21:59pm
Comments
senguptaamlan 16-Sep-10 5:18am
   
I think you don't know how to invoke the javascript function...also go through the line Page.ClientScript.RegisterStartupScript and what it does...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

CP VB / C# Javascript Article


Start with some background reading on the subject above is a CodeProject Article
  Permalink  
Comments
Dalek Dave 16-Sep-10 11:16am
   
Good Link
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

this is really strange

i have the following code in one aspx file

Dim link As String = "collection.aspx?SettleID=" & ViewState.Item("SettleID")
                           If (Not ClientScript.IsStartupScriptRegistered("OpenPage")) Then
 
                               Page.ClientScript.RegisterStartupScript _
                                                   (Me.GetType(), "OpenPage", "window.open('" & link & "');", True)
 
                           End If
it manages to open a new window with the url

when i try to use the same script on other pages, it does not work!
what could be the issue?
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

page.clientscript.registerscriptblock(me.gettype(),"alert","alert('Invalid username',true)"
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

You can show hide your from code behind by just adding
<div id="div1"  runat="server"><div /></div>

and in code behind

div1.Attributes.Add("style","display:none"); 


or to hide div in code behind you can just write
div1.visible = false
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 19 Dec 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100