I have a static page that contains a form.
<form METHOD="post" ACTION="...">
<input type="submit" value="Verzenden" />
</form>
When the submit button is clicked, I want the form fields to be sent to an ASP.NET page, in which I receive the form fields and do something with them (like sending a mail).
I was thinking to do something like this:
<form METHOD="post" ACTION="http://localhost:3384/mail.aspx">
<input type="submit" value="Verzenden" />
</form>
But how can I receive this data in the mail.aspx code behind?
Thanks
<form action="Default.aspx" method="post">
<input type="text" name="fullname">
<select name="color">
<option value="Red">Red $10.00</option>
<option value="Blue">Blue $8.00</option>
<option value="Green">Green $12.00</option>
</select>
<select name="size">
<option value="Small">Small</option>
<option value="Large">Large</option>
</select>
<input type="submit" value="Verzenden" />
</form>
protected void Page_Load(object sender, EventArgs e)
{
FullNameLabel.Text = Request.Form["fullname"];
ColorLabel.Text = Request.Form["color"];
SizeLabel.Text = Request.Form["size"];
}
Just use the Request.Form collection:
string verz = Request.Form["Verzenden"];
etc...
Doing this in Page_Load is easiest. It's probably best to avoid having a typical postback form on that page, just to keep things simple; otherwise, you have to test for IsPostBack to make sure you should read the Form values.
or from the queryString
Request.queryString["fieldname"];
Related
I am struggling with the following problem. I have in my .Net 4 application with Razor Page a database query that is started with a button (upper part in the code) and now I want to send the value of the radio button group (lower part in the code) with it, is this feasible and if so how? I would like to do this, if somehow possible, only with one button. Maybe this is also possible with a ViewBag variable?
How would you do that?
Many thanks in advance.
<form method="post" id="queryForm" asp-controller="HomeController">
<div class="input-group">
<select id="sqlQuerriesDropDown" class="form-select" name="selectedQuery">
#foreach (var SqlQuery in ViewBag.SqlQuerriesDropDown)
{
<option value="#SqlQuery.getQueryName()">#SqlQuery.getQueryName()</option>
}
</select>
<p> </p>
<!-- Schaltfläche Anzeigen -->
<input type="submit" class="btn btn-primary" value="View result"/>
<p> </p>
</div>
<div>
<br />
<label><b>Decimal separator</b></label><br />
<label><input class="boost_radio" onklick="boostNo(1)" asp-for="Boost_No.Number" type="radio" name="mySeperator" value=0 ViewBag.RB="0" checked="checked" /> Comma</label><br />
<label><input class="boost_radio" onklick="boostNo(2)" asp-for="Boost_No.Number" type="radio" name="mySeperator" value=1 ViewBag.RB="1" /> Point</label><br />
<span asp-validation-for="Boost_No.Number"></span><br />
<input type="submit" value="submit" name="myDelimitter" id="submit" />
</div>
</form>
This codes should help you. Please replace your controller names.
public ActionResult Index(FormCollection form)
{
string[] optionArray = Request.Form.GetValues("selectedQuery");
return View();
}
A last point is I strongly recommended to use models instead of viewbag.
i am creating a web app and i have a dropdownlist
<select id="drdsearch" ng-model="drd" style="margin-top:-39px; margin-left:300px; height:30px; width:200px; font-size:12px;"><option value="select">select</option>
<option value="default">Default</option>
<option value="venue">Venue Name</option>
<option value="date">Date</option>
</select>
with these textboxes
<input type="text" ng-hide="true" ng-show="drd=='default'" placeholder="d" name="default">
<input type="text" ng-hide="true" ng-show="drd=='venue'" placeholder="e" name="venue name">
<input type="text" ng-hide="true" ng-show="drd=='date'" placeholder="l" name="Date">
i used angularjs for (hide/show)textboxes but now when i run my program dropdown automatically included an extra blank option field
now there are four fields in my dropdow
1st ( )blank
2nd default
3rdvenue
4thDate
what i need to do to remove the extra (blank option) from the dropdownlist
Initialize the value in your $scope.drd with 'default' and you should be fine.
By using WebClient in C#, I can get the source of a page. Imagine that this HTML source always contains a form with a given name like this:
<form name="myform" action="page.php">
<input type="text" name="mytext" value="default text">
<textarea name="mytextarea">content</textarea>
<input type="password" name="mypass" value="12345">
<input type="hidden" name="myhiddenfield" value="code">
<input type="checkbox" name="mychb1" value="true" checked>
<input type="checkbox" name="mychb2" value="true">
<input type="radio" name="myradio" value="radio2" checked>
<input type="radio" name="myradio" value="radio1">
<select name="mychoice">
<option value="cherry">cherry</option>
<option value="orange">orange</option>
<option selected="" value="apple">apple</option>
</select>
<input type="submit" value="Submit">
</form>
Now I want to make POST data according to these values like this:
mytext=default text&mytextarea=content&mypass=12345&myhiddenfield=code&mychb=true&myradio=radio2&mychoice=apple
Note that mychb2 is not included because is not checked and also the names might be vary in each page source and there might be more or less than elements in the forms.
How can I do this?
I'm trying to append data from a form to the Url of my page using Razor (adding a query string). I've done this in ASP.NET Web Controls okay, but I would prefer to do this in Razor if it is possible?
Here's a very basic version of my Razor script but currently the '#test' variable is empty on post:
#{
<form id="test" method="post">
<input type="text" />
<input type="submit" value="Submit" />
</form>
if(IsPost){
var test = Request.Form["test"];
Response.Redirect(#Model.Url + "?test=" + #test);
}
}
As a sidenote, is there a way of achieving this without a POST method at all?
As I understand you want to add input value in your test variable. You should define id for input[text] or you should change it to
Page:
#using (Html.BeginForm("ActionName", "ControllerName", FormMethod.GET, null))
{
<input type='text' name'test' id='test' />
<input type="submit" value="Submit" />
}
or your code
#{
<form method="get" action="#Model.Url">
<input type="text" name="test" id="test" />
<input type="submit" value="Submit" />
</form>
}
P.S. I'm not clearly understand your code, because you set POST method and want to process GET method.
my query is , i have a combo box inside my form in html , i would like to pass the value of the selected item of the combo box to the server side which is a aspx page,
<form method="POST" action="page.aspx">
<input id="customerName" name="customerName" type="Text" />
<input id="customerPhone" name="customerPhone" type="Text" />
<select id="combobox" >
<option>df</option>
<option>as</option>
</select>
<input
</form>
value="Save" type="Submit" />
in the server side i use the following set of codes to select the textbox value
string n = String.Format("{0}", Request.Form['customerName']);
but how to get the values of the combo box selected value
please help me
thanks in advance
You can try fixing your html:
<form method="POST" action="page.aspx">
<input id="customerName" name="customerName" type="text">
<input id="customerPhone" name="customerPhone" type="text">
<select id="combobox" name="combobox">
<option value="df">df</option>
<option value="as">as</option>
</select>
<input value="Save" type="submit">
</form>
The selected value will be posted as Request.Form['combobox']