Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is the JavaScript function that I'm calling:

JavaScript
<script type="text/javascript" language="javascript">
        function divConfirm(data) {
            document.getElementById('data').innerHTML=data;
            document.getElementById('divConfirmPrompt').style.visibility = "visible";
        }
 </script>



The below Div tag I'm using to display the Messagebox in the Webform:

ASP.NET
<div id="divConfirmPrompt" style= "position:absolute;z-index:1000; width:350px;height:150px;border: solid black 1px; padding: 10px;background-color:rgb(212,208,200);visibility:hidden;top:38%;left:41%;vertical-align:middle" align="center" >
         
         <span id="data"> </span>
        <asp:button runat="server" id="btnClsYes" text="OK" CssClass="button" style="margin-left :15px;margin-top:25px" onclick="btnClsYes_Click" />                
     </div>  



I'm calling the above JavaScript function from CodeBehind:

C#
ScriptManager.RegisterStartupScript(this, typeof(Page), "OnClientClicking", "divConfirm('" + "Error message" + "');", true); 


As of now I'm implementing the same JavaScript function and div tag in all the pages to display the Message box in ASP.NET Webform...rather I want to write the same JavaScript function and the div tag in one .js file and I want to take the reference of that page and to all other pages...is it possible? and may I know how to implement the div tag in .js file?

What I have tried:

I'm trying to display the below Div tag in .js:

ASP.NET
<div id="divConfirmPrompt" style= "position:absolute;z-index:1000; width:350px;height:150px;border: solid black 1px; padding: 10px;background-color:rgb(212,208,200);visibility:hidden;top:38%;left:41%;vertical-align:middle" align="center" >
         
         <span id="data"> </span>
        <asp:button runat="server" id="btnClsYes" text="OK" CssClass="button" style="margin-left :15px;margin-top:25px" onclick="btnClsYes_Click" />                
     </div>  
Posted
Updated 10-Mar-16 1:42am
v7
Comments
Wombaticus 4-Mar-16 6:16am    
I'd suggest that instead of using "visibility" use "display":
In your div tag style use display:none;
In your js use document.getElementById('divConfirmPrompt').style.display='inline';
...might help.

1 solution

use your JavaScript as

JavaScript
function divConfirm(id,data) {
           document.getElementById(id).innerHTML=data;
           document.getElementById(id).style.visibility = "visible";
       }


where id is the id of div in which you want to display message. Now, just call this method from where you want by passing parameters like, id of div and data want to display.
 
Share this answer
 

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