request.form for dropdownlist value
i need to get value of selected item of dropdownlist using Post Method (request.form).
request.form["DropDownList"];
how can i get selectedvalue开发者_C百科 ,selectedindex or selecteditem.text ....
Try this (assuming the ID of your DropDownList
is DropDownList1
:
Request.Form[DropDownList1.UniqueID]
This way you can obtain a selected value.
string value=Request.Form["DropDownList1"];
With the method you are requesting. It can't be done.
That being said. If you are doing a Cross Page Postback, then that is one case where you can access the previous pages objects in it. Otherwise, if you don't have that type of control, then, you likely can't get to them.
In simple terms, you'd do a form on Page1.aspx like so
<form PostBackUrl="~/Page2.aspx" runat="server" id="frm">
On Page2.aspx, along with some other code, using the PreviousPage, you can do something like so:
((DropDownList)Page.PreviousPage.FindControl("DropDownList")).SelectedValue;
References:
How to: Post ASP.NET Web Pages to a Different Page
Cross-Page Posting in ASP.NET Web Pages
You can obtains the value from
Request.Form["DropDownList1"]
but if the ID of the drop down list is not static, you can do this..
Create a temporary static variable in some global.cs file
public class Global
{
public static string ddlID="";
}
and in .aspx.cs file where the drop down list is place.
Global.ddlID = DropDownList1.UniqueID
and on post pack
if (this.Request.Form["__EVENTTARGET"] == Globals.ddlID) {
//Perform action here, This postback is caused by **DropDownList1**
}
精彩评论