Please, I'm stuck trying to send my radio button user choice to the aspx.cs file and sent it to SQL, so here's the code:
<div class="form-group">
<label class="control-label col-sm-3">Status</label>
<div class="col-sm-6">
<div class="row" id="row" runat="server">
<div class="col-sm-4">
<label class="radio-inline">
<input type="radio" id="nsent" value="nsent" name="status" runat="server" checked="true">Not Sent
</label>
</div>
<div class="col-sm-4">
<label class="radio-inline">
<input type="radio" id="sent" value="sent" name="status" runat="server">Sent
</label>
</div>
</div>
</div>
So after I click Submit, there's a code to send it to SQL, but I don't have any idea how I would send the value selected in the HTML.
Selected Item or Selected Value won't work, even InnerText.
for a radio button, and in WEBFORMS, you would look at both control's CHECK state
if (sent.Checked) == true {...}
if (nsent.Checked == true) {...}
Alternatively you could review the FORMS collection that was submitted with the Page.Request (if this is a POSTBACK).
if (page.request.forms["status"] == "sent") {
...
} elseif (page.request.forms["status"] =="nsent" {
...
}
A third option, which seems to be outside the scope of your question is to read the radio buttons on the client side, and submit the value to the server via some AJAX style submission.
You should use <asp:Checkbox> (ASP.NET WebForms) or #Html.CheckBoxFor() (ASP.NET MVC).
Related
Using ASP .Net Core (Version 2.2, NON-MVC)
I have a database field (Car) which contains text, in HTML format.
I am using an ASP .Net "Input" Helper Tag to display the data (read only) on a webpage.
<input asp-for="Car.Description" asp-format="" disabled class="form-control" />
I would like to display the data as Html.Raw, but am unsure how to do so.
I originally thought I could do something like this (use Html.Raw), but this throws an exception:
<input asp-for=#Html.Raw(Car.Description) asp-format="" disabled class="form-control" />
I then thought the "asp-format" field might have some usable options, but I don't see any.
<div class="form-group row">
<div class="col-2">
<label asp-for="Car.Description"></label>
</div>
<div class="col-10">
<input asp-for="Car.Description" asp-format="" disabled class="form-control" />
</div>
</div>
End result is that I would like to have the display "raw" HTML on the screen.
Thanks
If you want to display the field as read only, you may not even need the "input" helper tag. Just displaying the data in the div should work.
Remove the input helper and just display the text in the div as follows:
<div class="form-group row">
<div class="col-2">
<label asp-for="Car.Description"></label>
</div>
<div class="col-10">
#Html.Raw(Car.Description)
</div>
</div>
Created a custom widget in Sitefinity MVC, with a custom widget designer:
<div class="form-group">
<label for="My Field">My Field</label>
<div class="row">
<div class="col-xs-3">
<input type="text" sf-model="properties.MyField.PropertyValue" class="form-control" id="MyField" />
</div>
</div>
</div>
Defined in both the controller and the model:
public string MyField { get; set; }
When I click edit, the field shows up as expected. I click save, and then hit edit again: value not stored. Does not help to refresh the page, and is not showing up in the widget itself either.
Am I missing a piece? The documentation is a little long-winded and scattered, I've been scouring through it but nothing is jumping out at me.
I see a put request sent in dev tools, but the request payload is empty. Not sure if this is the right request or relevant.
sf-model should be ng-model
<div class="form-group">
<label for="My Field">My Field</label>
<div class="row">
<div class="col-xs-3">
<input type="text" ng-model="properties.MyField.PropertyValue" class="form-control" id="MyField" />
</div>
</div>
</div>
The div contain html controls like dropdown , textboxes etc.Dropdown data is binding using c# code . when a dropdown repeats the binded data must be repeat . how can i implement it using jquery ?
You can add repeated div using bellow code: Working Fiddle
<input type="button" value="Add More(+)" id="btnAddMore" /> <br/>
<div id="divMain"></div>
<div id="divToCopy" style="display:none;">
<div>
<label>Text: </label>
<input type="text"><br/>
<label>Dropdown: </label>
<select>
<option>value1</option>
<option>value2</option>
</select>
</div>
</div>
Jquery Code:
$("#btnAddMore").click(function(){
var divCopy=$("#divToCopy").html();
$("#divMain").append(divCopy);
});
Here I made a simple webpage to post pictures, text, etc. I also made a simple ajax file to send the text, picture, etc to the database, and retrieve that information to be displayed in the same webpage. Here is the main webpage:
<div class="here" id="here">
#foreach (var photo in db.Query(photos, galleryInfo)){
<div class="com_1 com_3">
<div class="com_4">
<div class="com_44">
<img alt="miniatura" style="margin-top: 0" src="#Href("~/Photo/Thumbnail2", photo.UserId, new { size="small" })" class="thumbnail-border thumb22" />
<div class="n-s">
<b>#photo.Nombre #photo.Apellido</b>
</div>
</div>
<div class="com_5">
#photo.Comment
</div>
</div>
<div class="comcom">
<div class="comcom1">
<form onsubmit="return fofon(this)" id="gog">
<input type="text" style="display: none" name="GroupId" value="#galleryInfo" />
<textarea class="texta"name="comment" placeholder="Write a comment..."></textarea>
<input type="submit" class="g_sub"/>
</form>
</div>
</div>
</div>
}
In case it gets confuse, this shows every post with a "comment section" below each one (we can call them "Commne2"). The ajax will get the text, picture etc, send it to the database, and post it to another file, which will be displayed here... in the #foreach{}.
Obviously, the posts do not "excist", so any javascript that affects that post, will not work, because that element does not exciste in this case.
So my problem is, how can I create an ajax file (javascript file) that affects the Comment2 so that I can comment a post?
I use DNN and C#. I've got a form with a lot of input and select HTML tag. At the end of form there is a . When I click on it, the page is reload but when I try catch data of form (with Request.Form['formName'] or Request['form']) I've got only empty field (and if I check the value of IsPostback, it's always false). But in the form tag there is value.
FILE View.ascx
<div class="row">
<div class="col-sm-2"> </div>
<div class="col-sm-4">
<label for="formCodiceCanile">Codice Canile</label>
</div>
<div class="col-sm-4">
<input type="text" name="formCodiceCanile" ID="formCodiceCanile" value="<%=InfoScheda.CodiceCanile %>" />
</div>
<div class="col-sm-2"> </div>
</div>
OTHER FIELD (such as input text, select and radio button)
<input type="submit" name="formRegistraScheda" id="formRegistraScheda" value="Registra scheda" />
I know that I can use (and if I use it, there isn't problem because catch the value in the asp:Textbox it's a joke) but in this case I can't use them.
How can I resolve this problem?
PROBLEM SOLVED: the button doesn't do the POST because I use a field's form in the URL to observe the page status. Now I remove this control and I use the IsPostback native variable of C# and the form work!