Getting value from a texbox in asp.net
I have a web page which contains multiple panels (used to show and hide various textboxes) and one particular panel contains textboxes that is used to edit records. However, when I am attemtping to update the table, the txtVendorName.Text.Trim() is blank.
SqlConnection con = new SqlConnection(strConn);
string sqlUpdateVendor = "usp_Vendor_Update";
SqlCommand cmdUpdateVendor = new SqlCommand(sqlUpdateVendor, con);
cmdUpdateVendor.CommandType = CommandType.StoredProcedure;
cmdUpdateVendor.Parameters.Add(new SqlParameter("@RecID", SqlDbType.VarChar, 50));
cmdUpdateVendor.Parameters["@RecID"].Value = Request.QueryString["Rec_ID"];
cmdUpdateVendor.Parameters.Add(new SqlParameter("@empid", SqlDbType.VarChar, 11));
cmdUpdateVendor.Parameters["@empid"].Value = txtEmpIDNumber.Text.Trim();
cmdUpdateVendor.Parameters.Add(new SqlParameter("@VendorName", SqlDbType.VarChar, 100));
cmdUpdateVendor.Parameters["@VendorName"].Value = txtVendorName.Text.Trim();
The code does not throw an error of any sort.
Any idea why the textbox does not contain a value?
Ok, setting the PostBackURL property of the submit button to开发者_StackOverflow社区 the PageABC.aspx resolved that issue. Anyone know how and why the postbackurl property would resolve something like this?
Try to step through this code with the debugger. See if there is a spelling mistake.
Make sure you aren't setting txtVendorName.Text to blank in your Load or PreRender events without checking for ispostback
When is this code being called? In an event on a button?
It's important to remember the ASP.NET page life cycle.
http://msdn.microsoft.com/en-us/library/ms178472.aspx
http://www.15seconds.com/Issue/020102.htm
If you are calling it in an event on the button, you may be setting it to blank somewhere earlier in the cycle. If you are doing it in page_load, use if (!Page.IsPostBack){} where you set it to blank, that way it will only blank it out the first time the page is loaded, and not right before you want to use it in the button event!
Are you dynamically creating your textboxes? If so, be sure you're doing so in the init, page lifecycle is a bit finicky and could cause your textboxes to have problems if you create them after the init(which is when controls are registered).
Ok, setting the PostBackURL property of the submit button to the PageABC.aspx resolved that issue. Anyone know how and why the postbackurl property would resolve something like this?
While clicking on submit button ,1st it point to page load event then button_click property.
So If you are unloading any textbox value on page load ..defi. it navigate null value .
精彩评论