开发者

Using hidden input variable in the base class to persist value across postbacks

开发者 https://www.devze.com 2023-02-04 08:29 出处:网络
In my base class: public 开发者_开发技巧abstract class BaseUserControl : System.Web.UI.UserControl

In my base class:

public 开发者_开发技巧abstract class BaseUserControl : System.Web.UI.UserControl
{
  protected System.Web.UI.HtmlControls.HtmlInputHidden MyID;

  //This is called when the page loads
  private void OnLoad()
  {
     MyID.Value = "testId";
  }

 protected void OnButtonClick(object sender, EventArgs e)
{
    string s = this.MyID.Value;
}

}

In my user control that inherits from BaseUsercontrol The ascx has:

<asp:Button id="btnTest" runat="server" OnClick="OnButtonClick" />

Why can't I use the hidden input variable this way??


If you are having an HiddenInputField in your .ascx with id= MyID and that's what you are trying to use then that is not how you do it.

You will need to do a FindControl.

Or You might want to provide more details about why and what exactly you want to achieve. Because there might be other possible ways to achieve what you are trying to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号