Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (1 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


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";

    }
Posted
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...

CP VB / C# Javascript Article


Start with some background reading on the subject above is a CodeProject Article
 
Share this answer
 
Comments
Dalek Dave 16-Sep-10 11:16am    
Good Link
this is really strange

i have the following code in one aspx file

VB
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?
 
Share this answer
 
VB
page.clientscript.registerscriptblock(me.gettype(),"alert","alert('Invalid username',true)"
 
Share this answer
 
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
 
Share this answer
 
v2

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



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