Altjen B. Altjen B. - 27 days ago 6
ASP.NET (C#) Question

how to activate the functions of a div in css after focusing in a textbox in asp.net?

I have a div with icon, and a textbox.

this is the code:

<div id="Backtb1">
<i class="fa fa-envelope" id="envelope" aria-hidden="true"></i>
</div>
<asp:TextBox ID="TextBox1" CssClass="TextButtons" runat="server" placeholder="Username" ></asp:TextBox>


and the css for both Backtb1 and textbox1:

.TextButtons {
position: relative;
border: none;

border-radius: 4px;
width: 130%;
height: 30px;

font-family: Calibri;
font-size: 120%;

font-weight: bold;

opacity: 0.6;
border: 1px solid #888;
background-color: #888;
margin-bottom: 2px;


-webkit-transition: width .35s ease-in-out;
transition: width .35s ease-in-out;


}
.TextButtons:focus{
width: 115%;
outline:0;

border: 1px solid;
border-color: orange;
opacity: 1;
}

#Backtb1 {
position: absolute;

top:0;
left:0;
opacity:0;
width: 130%;
color: white;
}
#Backtb1:focus {
background-color: orange;
opacity:1;
}


I am trying to call the Backtb1 events after textbox1 gets focus.
So, the Backtb1 should get the opacity to 1 after I click the textbox1.

how can this be done? just on css or should I use jquery or javascript?

EDIT: since Vishal Kumar Sahu wanted full page code. this is it:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Dope.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="assets/CSS/LoginStylesheet.css" rel="stylesheet" />
<link href="assets/fontawesome/css/font-awesome.css" rel="stylesheet" />
<link href="assets/fontawesome/css/font-awesome.min.css" rel="stylesheet" />

<script type = "text/javascript">
function displayNextImage() {
x = (x === images.length - 1) ? 0 : x + 1;
document.getElementById("img").src = images[x];
}

function displayPreviousImage() {
x = (x <= 0) ? images.length - 1 : x - 1;
document.getElementById("img").src = images[x];
}

function startTimer() {
setInterval(displayNextImage, 7000);
}

document.addEventListener("DOMContentLoaded", function (event) {
startTimer();
});

var images = [], x = -1;
images[0] = "assets/Images/Image1.jpg";
images[1] = "assets/Images/Image2.jpg";
images[2] = "assets/Images/Image3.jpg";
images[3] = "assets/Images/Image4.jpg";

$("#textbox1").focus(function () {
$('#Backtb1').css("opacity", "1");
});

</script>

</head>
<body>
<form id="form1" runat="server">
<div id="CenterContents" onload = "changeImage()">
<%-- write everything here --%>
<%-- backgroundimage --%>
<img id="img" src="assets/Images/Image3.jpg">

<div id="Shadows">

</div>

<div id="CenterPanel">
<div id="wot">

<div id="Backtb1">
<i class="fa fa-envelope" id="envelope" aria-hidden="true"></i>
</div>
<asp:TextBox ID="TextBox1" CssClass="TextButtons" runat="server" placeholder="Username" ></asp:TextBox>

<asp:TextBox ID="TextBox2" CssClass="TextButtons" runat="server" placeholder="Password"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>


<%-- dont write anything lower than this --%>
</div>
</form>
</body>
</html>

Answer

It is possible with CSS-only using the ":focus hack" when you switch the position of the textbox and the backtb1-div in the html code. Because you set an absolute position to backtb1 this should be a possible solution for you.

Run the code snippet and you'll see the backtb1 appearing and disappearing when the textbox gains/loses focus:

#backtb1 {
    display: none;
    background-color: red;
    color: white;
    border-radius: 7px;
    max-width: 100px;
    font-family: sans-serif;
    font-weight: bold;
    text-align: center;
    margin: 4px 0 0 0;
}
#textbox1:focus ~ #backtb1 {
    display: block;
}
<input type="text" id="textbox1">
<div id="backtb1">
    <i class="fa fa-envelope" id="envelope" aria-hidden="true">Test</i>
</div>