MVC: Arrange a Docked Web.TextControl with a Custom Bar at the Top
Position a docked Web.TextControl below a custom toolbar bar in an MVC view by using CSS and JavaScript to offset the editor. The tutorial wraps the control in a DIV, sets absolute positioning with a 50px top offset, and adjusts the height dynamically on browser window resize.

Consider the following task: The Web.TextControl should be arranged under a custom bar that is located at the top of the page like in the following screenshot:

Objects such as DIV elements doesn't really have an option to extend itself to 100% of the remaining space on a page. The CSS Height property set to 100% works only, if the container element has a defined height.
For this reason, we implemented the Dock property that defines how the control is docked to its container or web site. This allows you to set the Web.TextControl to full screen or fill a container.
But the described scenario cannot be realized only by using the Dock property. Custom Javascript is required to resize TX Text Control when the browser Window is resized. The view contains a DIV that represents the custom bar at the top and the HtmlHelper for the Web.TextControl is wrapped by another DIV that is used to manipulate Web.TextControl using Javascript.
<div class="custom-bar">
Custom bar at the top
</div>
<div class="editor">
@Html.TXTextControl().TextControl(settings =>
{
settings.Dock = DockStyle.Window;
}
).Render()
</div>
The following CSS style code shows the definitions for the two DIV elements in our view:
div.custom-bar {
background-color: black;
height: 50px;
width: 100%;
color: white;
overflow-x: hidden;
overflow-y: hidden;
white-space: nowrap;
text-align: center;
}
div.editor {
width: 100%;
margin: 0;
padding: 0;
height: 300px;
}
In the Javascript, Web.TextControl is shifted down 50px using the CSS Top property and at the same time, the Height is decreased by 50px. This makes space for the custom bar at the top of the page.
<script>
// re-arrange TextControl to fill browser Window
function arrangeTextControl() {
$(".editor").children().first().css("top", "50px");
$(".editor").children().first().css(
"height", window.innerHeight - 50 + "px");
}
// attached resize events and re-arrange the controls
if (window.attachEvent) {
window.attachEvent('onresize', function () {
arrangeTextControl();
});
}
else if (window.addEventListener) {
window.addEventListener('resize', function () {
arrangeTextControl();
}, true);
}
arrangeTextControl();
</script>
Download the sample from GitHub and test it on your own.
![]()
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2012 or better
- TX Text Control .NET Server (trial sufficient)
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
MVC: Loading Files from the Backstage Menu
An MVC partial backstage view lists available files from a directory using a simple document model. When a user clicks a file, JavaScript sends an AJAX request to an HttpPost controller method…
MVC: Replace the File Menu with a Backstage View Menu
Replace the Web.TextControl File menu with a full-page backstage view using JavaScript and CSS. The tutorial disables the default FILE ribbon handler, renders a vertical navigation panel with…
MVC: Replace the Ribbon Table Menu with a Quick Insert Table Drop-down
Replace the default Web.TextControl ribbon table button with a grid-based quick insert dropdown using JavaScript. The tutorial renders a visual row-and-column picker, sends the selected dimensions…
MVC: Autosave and Restore Documents to and from the Local Browser Storage
Web.TextControl documents are autosaved to browser localStorage at five-second intervals using the JavaScript saveDocument method. On page reload, the ribbonTabsLoaded event checks for stored…
MVC: Loading and Saving Documents Through Controller HttpPost Methods
Web.TextControl X13 for ASP.NET MVC provides document load and save operations through controller HttpPost methods. The JavaScript API serializes documents as Base64, posts them via jQuery AJAX to…
