C# 如何在页面加载方法中获取参数?
我有这个控制:C# 如何在页面加载方法中获取参数?,c#,asp.net,pageload,asp.net-controls,C#,Asp.net,Pageload,Asp.net Controls,我有这个控制: <asp:DropDownList ID="ddlPaging" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPaging_SelectedIndexChanged"> </asp:DropDownList> 当我在DropDownList postBack中进行选择并启动此功能时: protected void Page_Load(object se
<asp:DropDownList ID="ddlPaging" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPaging_SelectedIndexChanged">
</asp:DropDownList>
当我在DropDownList postBack中进行选择并启动此功能时:
protected void Page_Load(object sender, EventArgs e)
{
string controlId= this.FindControl(this.Request.Params.Get("__EVENTTARGET")).ID
//always empty
string ctrlarg1 = this.Request.Params.Get("__EVENTARGUMENT");
string ctrlarg2 = Request.Form["__EVENTARGUMENT"];
string ctrlarg3 = Request.Params["__EVENTARGUMENT"];
string ctrlarg4 = this.Request["__EVENTARGUMENT"];
string ctrlarg5 = this.Request.Params.Get("__EVENTARGUMENT");
if (!isPaging)
{
ddlPaging.Visible = true;
ddlPaging.DataSource = Enumerable.Range(0, features.Count()).ToList();
ddlPaging.DataBind();
}
}
当启动Page_Load方法时,我需要在dropdownlist中获取所选项目
我试着这样做:
string ctrlarg1 = this.Request.Params.Get("__EVENTARGUMENT");
string ctrlarg2 = Request.Form["__EVENTARGUMENT"];
string ctrlarg3 = Request.Params["__EVENTARGUMENT"];
string ctrlarg4 = this.Request["__EVENTARGUMENT"];
string ctrlarg5 = this.Request.Params.Get("__EVENTARGUMENT");
string controlId= this.FindControl(this.Request.Params.Get("__EVENTTARGET")).ID
但结果是空的
当我以这种方式获得控制ID时:
string ctrlarg1 = this.Request.Params.Get("__EVENTARGUMENT");
string ctrlarg2 = Request.Form["__EVENTARGUMENT"];
string ctrlarg3 = Request.Params["__EVENTARGUMENT"];
string ctrlarg4 = this.Request["__EVENTARGUMENT"];
string ctrlarg5 = this.Request.Params.Get("__EVENTARGUMENT");
string controlId= this.FindControl(this.Request.Params.Get("__EVENTTARGET")).ID
它工作完美
所以我的问题是,如何在页面加载方法中的dropdownlist中获取选中的项目?我建议您不要在页面加载中这样做。DropDownList类上有一个SelectedIndexChanged事件正好用于此目的
<asp:DropDownList runat="server"
ID="_ddlMyDdl"
AutoPostBack="True"
OnSelectedIndexChanged="MyEventHandler"/>