Binding data to textbox, making it uneditable - c#

I have a textbox which I would like bound with data from the logged in user, so that the user can't edit it. Would this need to be a label, or is there another way?
<p>Practice:
<input class="form-control" type="text" value="6666666 - Siya's Awesome world" readonly="readonly" id="txtName" />
</p>
Ps. I don't want the values entered as I did above. Your help is appreciated.

Use input like this :
<input readonly="readonly" disabled="disabled" class="text-box single-line readonly" id="field-id" name="field-name" />

Related

Bind radiobuttons to two different fields with Angular

need some help on radio buttons. How can i bind 2 radio buttons that are for one particular question but use 2 different fields in the database. For example there is a question that has a Yes/No answer. The yes answer binds to one field, and the No answer to another, they don't bind to a single filed that has a true, false value.
<div class="radio-s">
<input type="radio" ng-value="true" data-name="use_plan"
data-value="true" ng-model="record.offer_plan" />
<label>Yes</label>
</div>
<div class="radio-s">
<input type="radio" ng-value="false" data-name="use_plan"
data-value="true" ng-model="record.offer_plan" />
<label>No</label>
</div>
Thanks in advance.
Attach the name attribute to both of your radio buttons so that only one can be selected at a time and also bind them to the respective fields from your DB
<div class="radio-s">
<input type="radio" name="planGroup" ng-value="true" data-name="use_plan"
data-value="true" ng-model="record.offer_plan_yes" />
<label>Yes</label>
</div>
<div class="radio-s">
<input type="radio" name="planGroup" ng-value="false" data-name="use_plan"
data-value="true" ng-model="record.offer_plan_no" />
<label>No</label>
</div>

Umbraco - how to insert a field that has spaces in it?

I have umbraco v7.2.8
I have some template code like this
<input type="hidden" name="search" value=#Request.QueryString["search"]>
this works well to put the query string value for search string into the hidden field so when i click the submit on the surrounding form it requeries.
However, when there are spaces in the search string, Umbraco gets way to clever for itself and changes something like "red tree" to "red" tree=""
It is frustrating and seems to happen for fields as well - this must be a common enough problem. I can URLEncode it but then when I click the submit button it gets encoded again, which obviously isn't desirable, so I basically want the following to happen
QueryString?Search=red+tree
template: <input type="hidden" name="search" value=#Request.QueryString["search"]>
becomes: <input type="hidden" name="search" value="red tree">
NOT: <input type="hidden" name="search" value="red" tree="">
note that <input type="hidden" name="search" value=#HttpUtility.UrlEncode(Request.QueryString["search"])> gives <input type="hidden" name="search" value="red+tree"> which is again not what I need
This isn't Umbraco, it's the fact that you haven't enclosed your value in quotes. If you amend your code to:
<input type="hidden" name="search" value="#Request.QueryString["search"]">
It should work as you expect.

How to avoid #Html.CheckBoxFor generating hidden field?

Using #Html.CheckBoxFor generates a hidden field. Is there a way I can avoid generating that ?
Why I want to do that ? I was provided design, which has some script or library used in it for visual display. It works fine if Html is in below format (Checkbox with Label):
<div>
<input type="checkbox" value="resources" id="resources" class="cb">
<label for="resources">
I need an offset facility
</label>
<i class="tooltip-icon" data-icon="repayments"></i>
</div>
But it do not work if there is a hidden field between Checkbox and Label:
<div>
<input id="HomeLoanLead_Redraw_flexibility_Value" class="cb" type="checkbox" value="true" name="HomeLoanLead.Redraw_flexibility_Value" data-val-required="The Redraw_flexibility_Value field is required." data-val="true">
<input type="hidden" value="false" name="HomeLoanLead.Redraw_flexibility_Value">
<label for="HomeLoanLead_Redraw_flexibility_Value"> I want to make extra repayments </label>
<i class="tooltip-icon" data-icon="loan"></i>
</div>
If I try using <input type=checkbox> I m afraid I will not get out of box model binding in post action.
Please help.

HttpContext.Current.Request.Form checkbox

I am posting my form to an MVC Controller, where I want to process some changes the user has made on a grid like html structure.
I have checkboxes rendered as simple HTML in my View for each row :
<input type="checkbox" id="cbxR1" checked="checked" />
<input type="checkbox" id="cbxR2" checked="checked" />
I would like to know how I would retrieve a checkbox value after an AJAX post.
I am trying to use the following to retrieve the
HttpContext.Current.Request.Form["cbxR1"]
and am always getting a null, regardless of whether the checkbox was checked or not.
The cbxR1, cbxR2 should be the name of an input element, not the id.
<form ...>
<input type="checkbox" name="cbxR1" checked="checked" />
<input type="checkbox" name="cbxR2" checked="checked" />
</form>

fill 2 form one field in common with C#

I need to fill two forms on the same website, my issue is the field because they have the same name, e.g. the password field in both forms is passed, so how can I fill both?
<form action="post.php" method="post">
<input type="hidden" name="name" value="value" />
<input type="text" name="image" />
<input type="password" name="pass" size="10" tabindex="7" accesskey="Q" value="">
</form>
<form action="post2.php" method="post">
<input type="hidden" name="name" value="value" />
<input type="text" name="image" />
<input type="password" name="pass" size="10" tabindex="4" accesskey="P" value="">
</form>
the code to fill fields I'm using is this:
WebBrowser1.Document.GetElementById("pass").SetAttribute("value", stringpassword);
thanks
The id attribute specifies a unique id for an HTML element.
The id must be unique within the HTML document.
The id attribute can be used by a JavaScript (via the HTML DOM) or by CSS to make changes or style the element with the specified id.
And if your specified website is not following the standard Html practices then you should write your own custom
code to access those controls and fill them straight away. You can use Regex Or Xpath for accomplishing this purpose.

Categories