How can I apply CssClass="form-control" to all textboxes within my master page? Any suggestions?
How can I apply CssClass="form-control" to all textboxes within my master page? Any suggestions?
Here are some steps you can take:
In the code behind of the master page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//added next line
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
var x = new object();
foreach (Control c in Controls)
{
foreach (Control masterControl in Page.Controls)
{
if (masterControl is MasterPage)
{
foreach (Control formControl in masterControl.Controls)
{
if (formControl is HtmlForm)
{
foreach (Control cont in formControl.Controls)
{
if (cont is TextBox)
{
((TextBox)cont).Attributes["class"] = "form-control";
}
}
}
}
}
}
}
}
}
}
In the aspx file of the master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="textbox1" />
<asp:TextBox runat="server" ID="textbox2" />
<asp:TextBox runat="server" ID="textbox3" />
<asp:TextBox runat="server" ID="textbox4" />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
For an easy way to style your control, simply add a CssClass attribute:
<asp:TextBox CssClass="form-control" runat="server"></asp:TextBox>
Just ensure that your Master Page includes a reference to Bootstrap in the Head section of your style:
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<%--Include Bootstrap Styles Below--%>
<link href="~/Styles/bootstrap.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</style>
I need help figuring out how to update my PHP webpage or table automatically in real-time without requiring a manual refresh. The current functionality of the page is working perfectly fine. Specifically, I want the page to instantly display any new user ...
A database stores family members on a family tree. A function is designed to query all relatives of a user and compile their contact information and metadata into a list of unique entries, regardless of order. The issue arises when the function only retri ...
After updating my TypeScript to the latest version, I keep encountering the following error: Cannot find type definition file for 'mocha'. tsconfig.json { "compilerOptions": { "emitDecoratorMetadata": true, "experimentalDecorators ...
Can you help me find a term for basic objects that accentuates their simplicity? Particularly, objects that do not reference themselves and do not have any methods or bindings (i.e. JSON-serializable). The terms I am currently using are: "flat object" " ...
I am looking to create a memory game using React for a portfolio project. I have an array of 20 items with 10 different sets of colors. const data = [ // Manchester Blue { ID: 1, Color: "#1C2C5B" }, ...
Below is a simplified version of HTML code containing 2 nested click events (one on the href and one on an input). When the user clicks on the input field, it inadvertently triggers the javascript function SelectTable() linked to the href event. This unint ...
I've been working on a website where users can have their avatars displayed using a JS function that loads 7 different images onto the page. These images correspond to different elements such as skin base, hair, eyes, mouth, shirt, shoes, and pants, a ...
I'm having trouble integrating Bootstrap 4 alpha SASS version with my ASP.NET 5 app. The installation process seems complex, especially with the Grunt file creating CSS and JS files. It's not clear how to streamline the workflow. My minimum goal ...
Hello, I am facing a dilemma. I need to apply category filtering to a JSON file but I am unsure of how to proceed with it. For instance, I wish to filter the 'vida' category along with its description and price. I seem to be stuck at this junctu ...
I'm in the process of developing a Discord bot and I'm interested in adding a unique feature to it. I want to create an interactive system where users can request help through DM with the bot, and the support team can respond through the bot as w ...
I'm currently utilizing jQuery to read a JSON file. However, I've encountered an issue where the old values are still being retrieved by the .get() function even after updating the file. As I continuously write and read from this file every secon ...
Currently, I am facing an issue while downloading a file. My goal is to perform an action immediately after the download is complete. Specifically, I aim to import a .js file as soon as it finishes downloading. var request = https.get('https://m ...
I am currently exploring the possibility of passing an array as the value for the property of an instance. In my model, I have set the dataType to STRING and I am inserting values from jQuery fields into an array which I then parse from the body and assign ...
Is it possible to add a class using jQuery when two specific conditions are met? 1) If the dropdown selection is either "acting" or "backstage" 2) If the membership status is set to "Non-member" If both of these requirements are fulfilled, I would like ...
I am currently coding an animated hamburger icon for the Bootstrap navbar, and I need to find a way to toggle both the hamburger icon and the responsive navbar. Is there a method or code snippet that allows me to toggle these two elements independently usi ...
My main objective is to convert TypeScript code to JavaScript. However, when I attempted to install the TypeScript compiler globally using 'npm install -g tsc', I encountered the following error: npm ERR! Error: EACCES: permission denied, rename ...
Seeking assistance to create a button with a 3D effect. I want to mimic the appearance of this button: https://i.sstatic.net/9sFs5.png Currently using Bootstrap to generate a button using this code: <button type="button" class="btn btn-primary">Gam ...
In my ASP.NET Web API application, I am dealing with two types of users - clients and drivers. Currently, I have separate methods in the client and driver controller for registering each type of user. However, I recently realized that the proper way to han ...
My webpage contains a video tag for playing online videos. Instead of just one, I have utilized two video tags. However, when attempting to play both videos simultaneously, they end up playing at the same time. I am seeking a solution where if I start pla ...
Can anyone explain to me why I am encountering the error mentioned above? I am unable to figure out the reason. Below is my code, please review it and suggest a solution for fixing this error. The objective is to upload multiple files to a specific locatio ...