JSFiddle - React, Tailwind, and code Playground

by Paul Leech

HTML

<div class="h1">ASP.NET ClientID Workaround</div>
One problem with this method is that it requires that I place the following hidden field in every page: <br /><br />
<code>&lt;asp:HiddenField runat="server" ID="prepended_ID_value" Value="dotNet_ID_Prefix" /&gt;</code><br /><br />
(and that's hardly the most elegant solution)
<input type="hidden" id="MasterPage_prepended_ID_value" value="A simulated ASP.NET ID" />

CSS

body { font-family:arial, helvetica, sans-serif; font-size:12px;}
code { color:#0000cc; }
.h1  { font-weight:bold;margin-bottom:5px;font-size:120%; }

JavaScript

$(document).ready(function() {
    var dotNetPrefix = $("[id$='prepended_ID_value']").attr('id');
    if (dotNetPrefix !== undefined) {
        dotNetPrefix = dotNetPrefix.replace('prepended_ID_value', '');
        dotNetPrefixID = '#' + dotNetPrefix;
        console.log('dotNetPrefix = ' + dotNetPrefix);
        testDotNet('prepended_ID_value');
    } else {
        console.log('Hidden Field is Missing! => <asp:HiddenField runat="server" ID="prepended_ID_value" Value="dotNet_ID_Prefix" />');
    }

});

function testDotNet(getID) {
    var test_dotNetPrefixID = $(dotNetPrefixID + getID).val();
    console.log('$(\'' + dotNetPrefixID + getID + '\').val() = ' + test_dotNetPrefixID);
}