4

I have a div inside asp:content :

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="slidebar" style="display:none;"  >There are some pending approvals.Please    approve    by the 25th of this month

<a href="#" id="slink" style="margin-left:10px;" onclick="fade('slidebar');">Click here to   close <sup style="font:caption;color:#373636;">X</sup></a>
</div>

<script language="javascript" type="text/javascript">
 function showbanner()
  {
   document.getElementById("slidebar").style.visibility="visible";
  }
</script>
<\asp:content>

and the code behind:

 ClientScript.RegisterClientScriptBlock(Page.GetType(), "displaybanner", "return  showbanner();", true);

I cannot call the function showbanner from the code behind and even when I directly call the statement inside showbanner with registerclientscript ...it doesnt get called .

Please help

4
  • Your aspx has <\asp:content> as the close tag for your first content placeholder. Was that a typo when posting, or is that in your code? Commented Mar 3, 2011 at 19:35
  • thats a typing error...no problem with the mark up Commented Mar 3, 2011 at 19:36
  • @abbas: My original answer was wrong, so I've deleted it. I'll look again and see what I can find. Commented Mar 3, 2011 at 19:48
  • Have you tried putting an alert('test'); inside showbanner, before calling document.getElementById, just to verify it's not firing? Commented Mar 3, 2011 at 19:51

3 Answers 3

4

The properties visibility and display are not the same, change the js function to:

function showbanner()
{
    document.getElementById("slidebar").style.display="block";
}

also change your code behind to

ClientScript.RegisterStartupScript(Page.GetType(), "displaybanner", "showbanner();", true);

so the script executes after the page has load or else it won't find the element.

Sign up to request clarification or add additional context in comments.

3 Comments

but the problem is that even if I add an alert ..it doesnt get fired...(inside the showbanner))
notice that I also removed the return, that caused a js error that stopped the script from running because you don't actually return anything from that function
I agree that is an error...but removed that and still its not working :(
0

I'm not sure why your register script isn't working but have you tried putting the javascript call directly on the page inside a script block? If that works then wrap the script block in a pannel at the bottom of the page with visible="false". In your code behind when you determine that you want it to work set the visibility to true.

If you are using Jquery I would also wrap the contents of your script block in:

$(document).ready(function() {
    //javascript call here
});

Just to make sure it doesn't get called before the page can actually handle it.

This all assumes of course that your function call is good and that the issue is with register client script.

2 Comments

One more thing I am calling this in the onload function...is that a problem??
Not sure but check out Equiso's answer. Looks like he has your problem nailed.
0

Okay one of my team mebers Mahi came up with a solution...rather than CleientScript.reg.....

we used Page.RegisterStartupScript and it works fine :))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.