简体   繁体   中英

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:

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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