简体   繁体   English

从html输入元素设置asp.net会话变量?

[英]set asp.net session variable from an html input element?

I have a form with an asp.net control button that has a postbackurl. 我有一个表单,带有一个带有postbackurl的asp.net控制按钮。 I am setting a session variable via a postback (to same page) from a dropdownlist and then I retrieve that session variable when the page is redirected to the postbackurl when clicking the button. 我正在通过下拉列表中的回发(到同一页面)设置会话变量,然后在单击按钮时将页面重定向到postbackurl时检索该会话变量。

Problem is, I need to add a search feature to this page also. 问题是,我还需要在此页面上添加搜索功能。 I cannot use an asp.net textbox control because of design issues in the clients page. 由于客户端页面中的设计问题,我无法使用asp.net文本框控件。

Is it possible to use an html input element and capture the typed value, and store it in an asp.net session variable on button click so I can retrieve it in another page? 是否可以使用html输入元素并捕获键入的值,并在单击按钮时将其存储在asp.net会话变量中,以便我可以在另一个页面中检索它?

I am using this code in page_load of the code-behind, of the page that has the search box (first page) 我在具有搜索框的页面(第一页)的背后代码的page_load中使用此代码

        PostBackOptions postBackOptions = new PostBackOptions(SearchButton);
        postBackOptions.ActionUrl = "/searchdesc";
        SearchButton.Attributes.Add("onclick",
        Page.ClientScript.GetPostBackEventReference(postBackOptions));

Is it possible to store a session variable in something like that? 是否可以将会话变量存储在类似的内容中? I have also tried using AJAX but It doesnt redirect on click. 我也尝试过使用AJAX,但单击时不会重定向。

Any help? 有什么帮助吗?

You can create any HTML input and add an attribute of runat="server" and set an ID also for that member, then you can attach your event handler if you wish and catch whatever value you need in the code behind. 您可以创建任何HTML输入并添加runat="server"的属性,并还为该成员设置ID ,然后可以根据需要附加事件处理程序,并在后面的代码中捕获所需的任何值。

HTML example: HTML示例:

<input type="text" id="yourCustomInput" runat="server" OnClick="YourCustomMethod" />

Code behind: 后面的代码:

protected void YourCustomMethod(object sender, EventArgs e)
{
  //your custom code 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM