473,588 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/hide divs according to server side variable

How would I show or hide a div that is using client side Javascript
based upon a server side variable?

Here are my divs :

<div id="idButton5" class="otherLef tBarLink" onmouseover="ja vascript:
changeStylesMou seOver('5');" onmouseout="jav ascript:
changeStylesMou seOut('5');" onclick="locati on='/AddProject.aspx '">
<div class="leftBarL inkText">
Add Project
</div>
</div>
<div id="idButton7" class="otherLef tBarLink"
onmouseover="ja vascript: changeStylesMou seOver('7');"
onmouseout="jav ascript: changeStylesMou seOut('7');"
onclick="locati on='/AddTask.aspx'">
<div class="leftBarL inkText">
Add Task
</div>
</div>

I want to use a variable that is being set in the Page_Load event to
determine whether I show or hide each of these divs.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
5 4465
Hi,

Put your variable's value in a hidden input ....
access the hidden input from javascript ...
and perform your operation

Best of luck

Munna

www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jun 27 '08 #2
How exactly would I do that?
*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3
In the page load event register some custom javascript to include on
the page, e.g.

protected void Page_Load(objec t sender, EventArgs e)
{
// build custom javascript string based on server parameter
string myJavascript = "var myParameter = '" + this.MyParamete r +
"';";
// register script on page
Page.ClientScri pt.RegisterClie ntScriptBlock(
Page.GetType(), "MyScript", myJavascript, true);
// now myParameter can be used in javascript code on the page
}
private string MyParameter
{
get { ... }
}
Alternatively you could put runat="server" on the divs and set the
Visible property as you would on a server control, but that's entirly
server side, not javascript.

Terry.

On Jun 20, 12:02*pm, Mike P <mike.p...@gmai l.comwrote:
How would I show or hide a div that is using client side Javascript
based upon a server side variable?

Here are my divs :

<div id="idButton5" class="otherLef tBarLink" onmouseover="ja vascript:
changeStylesMou seOver('5');" onmouseout="jav ascript:
changeStylesMou seOut('5');" onclick="locati on='/AddProject.aspx '">
* * * * <div class="leftBarL inkText">
* * * * * * Add Project
* * * * </div>
* * </div>
* * <div id="idButton7" class="otherLef tBarLink"
onmouseover="ja vascript: changeStylesMou seOver('7');"
onmouseout="jav ascript: changeStylesMou seOut('7');"
onclick="locati on='/AddTask.aspx'">
* * * * <div class="leftBarL inkText">
* * * * * * Add Task
* * * * </div>
* * </div>

I want to use a variable that is being set in the Page_Load event to
determine whether I show or hide each of these divs.

*** Sent via Developersdexht tp://www.developersd ex.com***
Jun 27 '08 #4
I am setting runat="server" on the divs and set the
Visible property as you would on a server control, but whenever my code
calls one of my Javascript functions I get the error 'object required'
when I am passing the div id to the function changeStylesMou seOver(id).
But this works fine when I don't set runat="server".

Any ideas why?

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #5
On Jun 20, 2:50*pm, Mike P <mike.p...@gmai l.comwrote:
I am setting runat="server" on the divs and set the
Visible property as you would on a server control, but whenever my code
calls one of my Javascript functions I get the error 'object required'
when I am passing the div id to the function changeStylesMou seOver(id).
But this works fine when I don't set runat="server".

Any ideas why?

*** Sent via Developersdexht tp://www.developersd ex.com***
The server side Visible property will cause the control not to be
rendered out to the browser.

To have it there but hidden change the CSS style properties of the
control rather than the Visible property.

Terry.
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1474
by: Jack | last post by:
Hello, <%@ Language=VBScript %> <% dim a a=10 'I want b=a at this place %> <Script language=VBScript> dim b </Script>
2
8324
by: Matt | last post by:
If I assign VBScript server side variable a to javascript variable x, it is fine. <% Dim a, b a = 10 %> var x = <%= a %>; alert(x); But if I do the other way around, then it has 500 error. any ideas??
1
2842
by: dspearing | last post by:
I'm new to asp, and was wondering how I could change the value of a server variable when the user clicks a button. The asp page displays a report using server side vbscript, and I have added an 'export' button that will copy the report to a file. I need this button to change a boolean so that the page will re-run, writing the report to the file instead of the screen.
4
4217
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is swapped with close.gif - subsequently, when close.gif is clicked, the div contents get hidden
6
5055
by: Dan | last post by:
Excuse me if i'm being a bit thick here, but is it possible to reference a server side variable within an embedded js source file. For example, my test.js file contains alert('<%=tmpVar%>'); and my aspx page contains:- <script type="text/javascript" src="test.js">
1
3042
by: ravindravarman | last post by:
I need to assing some value from the java script variable in the .aspx page to a server side variable in the .aspx.cs page. Can any one help me with this? Thanks, Ravi
0
936
by: tommyguns | last post by:
I am working with SQL server and I am trying to write a server side variable to call for the record set (the webpage code is .asp) that is being entered on the website when the button on the website (submit button) is clicked. Not sure If I stated that clearly enough. I am extremly new to this. Thanks, Tom
3
1927
by: Sarah W | last post by:
Forgive me, I'm still pretty newb with javascript. I was asked to start updating a webpage for an organization I belong to, and I'd like to make it a bit easier to read. Before I get too far, the current page is located http://www.northshield.org/Posts/Display.aspx?ID=8 As you can see, it is very long, and pretty confusing. What I'd like to do is for each name level, use a show/hide div for the one under it. For example, all of the...
1
4277
by: ll | last post by:
I'm currently working on a form which consists of a show and hide javascript. The toggle works fine, although when I click on submit, I would like the page to reload with the toggle (show/hide) div in the same state it was before being submitted. E.G. If the div was visible, I'd like for it to be visible upon return. Here's the script I'm currently using - thanks for any help, Louis --------------------------------------------
0
7860
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5726
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3883
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2371
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.