Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   ASP.NET (http://www.programmingforums.org/forum35.html)
-   -   hiding / showing a div from code behind (http://www.programmingforums.org/showthread.php?t=14041)

paulchwd Sep 25th, 2007 5:13 PM

hiding / showing a div from code behind
 
Hi .. I have a dvi in the aspx page that is set to hidden, I want to set it to visible from my c#code behind file when the execution of the program completes. (and no exceptions are thrown)

how can I do this ?

DaWei Sep 25th, 2007 5:30 PM

Paul, you're asking a train of relatively simple questions. Have you read the documentation (or even Googled)? Just curious.

paulchwd Sep 25th, 2007 5:37 PM

Thanks for you reply, I search google extensively, all I could find was how to add javaScript onClick events and such to a button.. i would like to unhide this div after the form data is saved successfully on the database and no exceptions are throw. ie right after command.ExecuteNonQuery();

paulchwd Sep 25th, 2007 8:32 PM

I saw code examples with RegisterStartUpScript.. and came up with this code but it doesnt do anything. How can i get the function to execute? Is it possible I can add an onLoad to the form tag (when the user pushes submit, which is also when this code is execute ) from the code-behind so this function will run when the pages loads ? Many thanks


Code behind file
:

string showDiv = " function showDiv() \n" +
                                  "{ \n alert('xx'); \n var myDiv = document.getElementById('fin_div'); \n" +
                                  "myDiv.visibility='visible'; \n" +
                                  "}\n";


This is the div code in the aspx file
:

<div id="fin_div" style=" left: 266px; width: 292px; position:relative; top: -708px; background-color: White; height: 131px; visibility:hidden; border-style:dashed;  border-width: thin; border-color: Black; visibility:hidden>
   
              <div style="padding-left: 5px; background-image:url(/resources/div_bg.gif); border-bottom-style:solid; border-bottom-width:thin; border-bottom-color: Black; ">
                <font face="arial" size="4" color="black"> Complete !</font>
                </div>
               
                <div style=" padding:5px;" >
                  <font face="verdana" size="2" color="black"> <br /> Thank you. You book has been added to BeatTheBookstore. Now buyers can see you book !</font>   
                </div>
          </div>


This is what is outputted into the html source:

:

<script type="text/javascript">
<!--
 function showDiv()
{
 alert('xx');
 var myDiv = document.getElementById('fin_div');
myDiv.visibility='visible';
}
// -->
</script>


DaWei Sep 25th, 2007 8:57 PM

That's fine, Paul, but you have to have something that calls showDiv if the div isn't visible to begin with. The function only does something if it's invoked.

paulchwd Sep 25th, 2007 10:03 PM

Sorry, I think i was unclear in my last post, and thanks for the response. That is my problem... I am able to write the function to the aspx file, but how do i get something to call it after the code behind file finishes execution ?

Thnx

Wizard1988 Sep 25th, 2007 10:10 PM

:

public void someFunction()
{
  doStuff();
  doMoreStuff();
  hideDIV();
}

Something like that??

DaWei Sep 25th, 2007 10:17 PM

Have your code behind file generate a call in the HTML. Generally, I put it before the </body> tag, but I might put it in on "on_init" function, if it's called for.

For the first option, just emit, as HTML,
:

<script type="text/javascript">
    showDiv ();
</script>
</body>


The browser has no idea of what you are doing on the server. When you write your code with a mixture of asp (or PHP, or anything else) and HTML, that is not an interactive scenario where the server does something and the browser does something and the server does something, and so on.

That is merely building the page, part of it with textual HTML, and part of it with the server program (asp, or whatever) emitting HTML. When the page is built, it is sent. The browser looks at that page and renders it.

If you wonder what the hell your browser is actually seeing, then just view source. That won't necessarily give you everything (the contents of files that you load with style or external script inclusions), but if you really need to see those at the client (you can see them on the server, since you wrote them), then read the RFC's and write a program that loads them just like the browser does.

EDIT: That won't work any better, wizard, because the page would still have to call "somefunction".

paulchwd Sep 25th, 2007 10:54 PM

It works! It works! Again, thanks for the reply i put a call to it as you said and It worked!

Out of curiosity, how do i stick the call to the function in before the <body> tag programatically.. i just stuck the call in at the top of the script i wrote

ie:

showDiv();
Function showDiv)(
{
etc...
}

DaWei Sep 26th, 2007 7:46 AM

The call should be in the body, after the div is rendered.


All times are GMT -5. The time now is 3:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC