Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi friends, I have small doubt like I have some ASPX pages.
in Site.Master page I have menu in that when I click a menu item some aspx page has to open but after open that page I want to open a div in that page which is by default set display=none.

I have tried by show and hide using jquery? but able to open that page but not the div. so I have tried changing the class attribute after page is opened. i want to do in javascript only.

Here is my code that i used
C#
var currentUrl = $(location).attr('href');
   //alert(currentUrl);
    var containsFoo = currentUrl.indexOf('Admin.aspx');
    alert(containsFoo);
    if (containsFoo!=-1) {
        $("#" + DivId).removeAttr('class', 'SearchDivOff');
        $("#" + DivId).attr('class','SearchDivOn');
    }
    else {
        window.open("Admin.aspx", "_self");
        $("#" + DivId).removeAttr('class','SearchDivOff');
        $("#" + DivId).attr('class','SearchDivOn');
    }


Here I have checked for that if the page is Admin.aspx if then open that div or else open that page first and then open particular div next. my problem is that when i am in some other page like Home.aspx I am just opening that page but not able to open that div.

how can I do this?
Thanks in Advance
Ganesh
Posted

Hope this helps you,

var divId = document.getElementById("ctl00_divContentPlace");
C#
divId .style.display = "none";
       divId .style.display = "block";


try using 'If' condition. where to display: none or display:block.
 
Share this answer
 
Comments
Ganesh KP 18-Oct-12 23:29pm    
I have used the condition but when I am not in Admin.aspx page it is thorwing error as "Unable to get the value of the property style:object is null or undefined"

What cause this error here is the code I have used

var containsFoo = currentUrl.indexOf('Admin.aspx');
if (containsFoo != -1) {

if (document.getElementById(DivId).style.display == "none") {
document.getElementById(DivId).style.display = "block";
}
else {
document.getElementById(DivId).style.display = "none"; //Error is coming here as above stated error.
}
}
else {
if (document.getElementById(DivId).style.display == "none") {
document.getElementById(DivId).style.display = "block";
}
else {
document.getElementById(DivId).style.display = "none";
}
window.open("Admin.aspx", "_self");
}
Unless your Admin.aspx page is loaded, you won't be able to remove or add an attribute. I think you need to have a check to make sure that the page is loaded using $(document).ready() before making your RemoveAttr() and attr() method calls. Why don't you try this?
 
Share this answer
 
Comments
Ganesh KP 18-Oct-12 0:33am    
In my code I have checked the Current Browser Url and if it is a Admin.aspx page then I am just opening the div in that page, when the current page is not admin.aspx then I am opening the admin.aspx page and after that particular div. but I am unable to do so that means I am able to open the div but not able to open the div after that page is opened. what may be the problem.
Why don't you move javacript that is specific to a given page into the page that needs it. Then you can just call it when the page has completed loading.
A master page shouldn't know that much about the children that inherit from it.
 
Share this answer
 
v2
Comments
Ganesh KP 18-Oct-12 0:36am    
I cant understand what you say? Even I move my code to that specific page how I am able to do that div open after that page has loaded, see here I am using that specific page in many ways to display all the necessary summary info and to search by Id option etc. so I cant do so in that way?

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