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!
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>
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).
So I have a form with a webbrowser in it. It needs to put some text into a text field input and then it has to press enter to send the text. But the problem I got is when I am doing something else it tries to press enter in that program I am currently using.
webBrowser1.Document.GetElementById("chatMessage").SetAttribute("Test");
webBrowser1.Select();
webBrowser1.Document.GetElementById("chatMessage").Focus();
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
Any idea on what I should use instead?
Here is the html code.
<form id="chatForm">
<div style="margin:5px">
<div class="form-group" style="margin-bottom:5px">
<input type="text" class="form-control" placeholder="Type here to chat..." id="chatMessage" maxlength="200" autocomplete="off">
</div>
<div class="pull-left">
<strong>Users Online: <span id="isonline">0</span></strong>
</div>
<div class="checkbox pull-right" style="margin:0px">
<label class="noselect">
<input type="checkbox" id="scroll">
<strong>Pause chat</strong>
</label>
</div>
<br>
<div class="pull-left">
Chat Rules
</div>
</div>
</form>
I don't think it is possible. All I could think of is focusing your application for a split second, send the keys and jump back to where you were. But this holds so many errors and will disturb you at least for a little moment that you won't be satisfied with it. Is there no chance for you to send the data/message on a direct way instead of simulating the keyboard input?
Checkout the key hook
C# : Keyboard Hook
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?
Bit of an odd one here:
The following razor syntax renders a nce simple html from with a submit button inside the bottom of it.
When i hit that button i would expect a postback to performed but for reason it dosn't ... any ideas??
Oh by the way this is the entire code for the view ...
#model FLM.PRL.EComms.Models.ReplySMS
#using (Html.BeginForm("Reply", "SMS", FormMethod.Post)) {
<h2>Follow Up</h2>
#Html.ValidationSummary(true)
#Html.HiddenFor(model => Model.From)
#Html.HiddenFor(model => Model.To)
<div class="editor-label">Reply</div>
<div class="editor-field">
#Html.EditorFor(model => Model.Message)
#Html.ValidationMessageFor(model => Model.Message)
</div>
<input type="submit" value="Reply" />
<br />
}
EDIT: Resulting markup generated by this view ...
<form action="/SMS/Reply" method="post">
<h2>Follow Up</h2>
<input data-val="true" data-val-required="The From field is required." id="From" name="From" type="hidden" value="xxxxxxxx" /><input data-val="true" data-val-required="The To field is required." id="To" name="To" type="hidden" value="xxxxxxx" /> <div class="editor-label">Reply</div>
<div class="editor-field">
<textarea class="text-box multi-line" id="Message" name="Message">
</textarea>
<span class="field-validation-valid" data-valmsg-for="Message" data-valmsg-replace="true"></span>
</div>
<input id="submitReply" type="submit" value="Reply" />
<br />
</form>
The only reason for this form not to be submitted are scripts interfering with the process. Maybe the validation scripts.
I noted that the Message field is required. Did you provided a value to this field? Don't you have any validation error message?
In the case validation is fine, I suggest removing selectively all the scripts from the page and see what happens. If removing a script results in your form working, you know it is the source of the problem.
I figured it out ... it's the hidden fields ... they are required but populated by the server during the postback so the auto validation prevents the postback client side before the server is able to populate the fields ...
solution:
Don't add empty required fields to an MVC form or turn off validation (not a good idea)