简体   繁体   English

回发后如何从文本框中检索文本?

[英]How to retrieve text from text box after postback?

I have some textbox's who's values are all empty when i try retrieve there values from the behind code after a post back submit. 我有一些文本框的值全为空,当我尝试在回发提交后从后面的代码中检索这些值时。

My submit button: 我的提交按钮:

<ICCM:ICCMImageButton ID="btnSubmit" runat="server" meta:resourcekey="btnResSubmit" onclick="btnSubmit_Click" PostBack="true" style="float:right; padding-right:5px;" TabIndex="23"/>

Behind C# code: C#代码背后:

protected void btnSubmit_Click(object sender, EventArgs e)
{
//code
objCmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = txtFName.Text.ToString();
//more code
}

Page load: 页面加载:

btnSubmit.ClickScript = "if(ValidatePage() == false){return false}; this.disabled = true; document.getElementById(this.getAttribute('ControlID') + 'Text').innerHTML = '" + Resources.ICCMCPortal.Submitting + "';";

OnInt: OnInt:

btnSubmit.Page = this.Page;

The text value is always "" unless i pre populated the textbox in the page load then the text will be that regardless if i made a change to it. 除非我在页面加载中预先填充了文本框,否则文本值始终为“”,而无论我是否对其进行了更改,文本都将是该文本值。

Set you textbox values inside here: 在此处设置文本框值:

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      SetTextboxValues();
   }
}

This way the wont be reset on postback. 这样,将不会在回发时重置。

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

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