Dynamically create checkbox with JQuery from text input

<div id=”cblist”> <input type=”checkbox” value=”first checkbox” id=”cb1″ /> <label for=”cb1″>first checkbox</label> </div> <input type=”text” id=”txtName” /> <input type=”button” value=”ok” id=”btnSave” /> <script type=”text/javascript”> $(document).ready(function() { $(‘#btnSave’).click(function() { addCheckbox($(‘#txtName’).val()); }); }); function addCheckbox(name) { var container = $(‘#cblist’); var inputs = container.find(‘input’); var id = inputs.length+1; $(‘<input />’, { type: ‘checkbox’, id: ‘cb’+id, value: name }).appendTo(container); … Read more

Converting dynamic type to dictionary C#

You can fill the dictionary using reflection: public Dictionary<String, Object> Dyn2Dict(dynamic dynObj) { var dictionary = new Dictionary<string, object>(); foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(dynObj)) { object obj = propertyDescriptor.GetValue(dynObj); dictionary.Add(propertyDescriptor.Name, obj); } return dictionary; }

Can script.readyState be trusted to detect the end of dynamic script loading?

In Opera, the script.readyState property cannot be trusted. For example, the readyState “loaded” may be fired before the script runs in Opera 9.64. I performed the same test in Opera 9.64 and Opera 10, with different results. In Opera 9.64, the onreadystatechange handler gets fired twice, once before and once after the script runs. The … Read more

How does ViewBag in ASP.NET MVC work behind the scenes?

ViewBag is a property of ControllerBase, which all controllers must inherit from. It’s a dynamic object, that’s why you can add new properties to it without getting compile time errors. It’s not static, it’s a member of the object. During the request lifetime, the controller instance is created and disposed, so you won’t have “concurrency” … Read more

The ‘import.meta’ meta-property is only allowed when the ‘–module’ option is ‘es2020’, ‘esnext’, or ‘system’.ts(1343)

If you are using VSCode and you have the module setting in typescript configuration set to ‘es2020’, ‘es2022’, ‘esnext’, ‘system’, ‘node12’, or ‘nodenext’. Then you might want to try simply restarting your typescript server. The quickest way would by hitting (ctrl+shift+p) and selecting restart typescript server. Picture attached.

How to call DynamicObject.TryGetMember directly?

I’m not sure if there’s any method in the framework that actually returns a GetMemberBinder, but it doesn’t matter – that isn’t the correct way to invoke a dynamic member by name. What you actually need to do is create a call site. The method looks like this: static object GetDynamicMember(object obj, string memberName) { … Read more

Create an instance of a React class from a string

This will not work: var Home = React.createClass({ … }); var Component = “Home”; React.render(<Component />, …); However, this will: var Home = React.createClass({ … }); var Component = Home; React.render(<Component />, …); So you simply need to find a way to map between the string “Home” and the component class Home. A simple object … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)