开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜