Getting the selected value of a combo box in server side - c#

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']

Related

C# Razor Pages writing Radio Button value into ViewBag or send it to controller

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.

How to convert HTML Form data into POST data in C#?

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?

How to access value of of input type="text" control of HTML5 in asp.net usercontrol + Umbraco

I am using ascx page. which I am injecting in UMBRACO.
following is my .ascx Code.
<form id="main-contact-form" name="contact-form" method="post" action="#">
<div class="form-group">
<input type="text" runat="server" name="name" id="txtName" class="form-control" placeholder="Name" required />
</div>
<button type="submit" class="btn-primary">Send Message</button>
</form>
I have try to get value of text box (txtName) from back end but I am not abe to access it.
I have tried following method to do so..(Where strtxtName is a string variable)
1) strtxtName = txtName.Value
2) strtxtName = Request.QueryString("txtName")
3) Request.Form.AllKeys -> return Nothing.
But not able to get value of text Box ,
I don't think Umbraco is making any issue.?

Calling an ASP.NET page from a form

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"];

How to send data from one page to another page with querystring and input form?

I am working in C#(asp.net). I have two pages 'abc.aspx' and 'xyz.aspx'. I want to send data from 'abc.aspx' to 'xyz.aspx'. I am using this code.
In 'abc.aspx'
<form action='xyz.aspx?site=google&code=123' method='get'>
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
Now, I want to access all three values (site,code and name1). But, in 'xyz.aspx', I got only one value i.e name1. How to get all three values.
You need to put the values into hidden <input /> elements and hard-code the values if you want to have them end up in the query string. You're correct in setting the method='get':
<form action='xyz.aspx' method='get'>
<input type='hidden' name='site' value='google' />
<input type='hidden' name='code' value='123' />
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
I think this one is the best.
In abc.aspx
<form action="xyz.aspx?site=google" method="post">
<input type="text" name="name1" />
<input type="submit" value="Submit" />
</form>
In xyz.aspx, access the data like this..
string site = Request.QueryString["site"];
string name = Request.Form["name1"];
//Remaining code...

Categories