Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: textboxes still showing old info after postback

Status
Not open for further replies.

jpuk

MIS
Aug 28, 2003
11
0
0
GB
I populate textboxes on a user control from a database. my problem is that the textboxes retain their old info after a postback. I use the page_load event to populate the fields. Strange thing is that a response.write of the textbox in the page_load routine shows the textbox as having the correct data but when displayed it shows the previous data. To add to confusion if i set the textbox to enabled = false after the update the correct data shows.

I've tried with viewstate and enabled and disabled but nothing.

Thanks in advance for any replies
 
when exactly are u setting the data to the textbox? in the page_load event? try the page_prerender event...

Known is handfull, Unknown is worldfull
 
vbkris,

Thanks for this but still get the same problem on the textboxes. Why would they work correctly once i set enabled to False.
 
Try posting your code so we can see what your problem may be...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
excuse the poor code as it's my first attempt

i have an aspx page that loads the user control - code is

private void Page_Load(object sender, System.EventArgs e)
{


if (!IsPostBack)
{
//This populate dropdowns - works fine
populateDDL(ddlBusRef, "Bus Case Ref");
populateDDL(ddlWorkRef, "Work ref number");
populateDDL(ddlKintanaRef, "Kintana Ref");
}
else {
Control Ctrl1 = Page.LoadControl("SingleRecordGrid.ascx");
phDataGrid.Controls.Add(Ctrl1);
}
}




User control(SingleRecordGrid.ascx) is just lots of text boxes - code behind page shows

private String sqlConn = ConfigurationSettings.AppSettings["MyDBConnection"];

private void Page_preRender(object sender, System.EventArgs e)
{
if (IsPostBack) {
String PBControl = Request.Params["__EVENTTARGET"];
String fName = "";

switch (PBControl)
{
case "ddlWorkRef" :
fName = "Work ref number";
break;
case "ddlKintanaRef" :
fName = "Kintana Ref";
break;
default :
fName = "Bus Case Ref";
break;
}

SqlConnection conn1 = new SqlConnection(sqlConn);
String strSelect = "select count(*) As rcount from workstack where [" + fName + "] = '" + Request.Params[PBControl] + "';" +
" select [Work ref number], [Bus Case Ref],convert(char,[Date initiated],106) As [Date Initiated]," +
" convert(char,[Date authorised],106) As [Date Authorised], " +
" 'Delivery Date' = CASE WHEN [Delivery date] = '' THEN '' ELSE CONVERT(CHAR,CONVERT(DATETIME,[Delivery date],103),106) END, " +
" 'Revised Date' = CASE WHEN [Revised Date] = '' THEN '' ELSE CONVERT(CHAR,CONVERT(DATETIME,[Revised Date],103),106) END, " +
" CONVERT(CHAR,CONVERT(DATETIME,[Date closed],103),106) As [Date Closed]," +
" [Project Title], [Feasibility], [Category], [Bus Case Status], [Work status]," +
" [Chargeable], [BT Prog No], [Sponsoring unit], [Sponsor name], [BT Del Con]," +
" [BT OneIT Con], [Client Manager], [Exec Manager],[ESBT lead]," +
" [A&FS lead], [Kintana Ref]" +
" from workstack where [" + fName + "] = '" + Request.Params[PBControl] + "'";

SqlCommand cmdWorkstackRecord = new SqlCommand(strSelect ,conn1);
SqlDataReader r1;

conn1.Open();

r1 = cmdWorkstackRecord.ExecuteReader();
r1.Read();

if (Int32.Parse(r1["rcount"].ToString()) < 1)
{

txtWorkRefNo.Text = String.Empty;
txtBusCaseRef.Text = String.Empty;
txtDateInitiated.Text = String.Empty;
txtDateAuthorised.Text = String.Empty;
txtDeliveryDate.Text = String.Empty;
txtDateRevised.Text = String.Empty;
txtDateClosed.Text = String.Empty;
txtProjectTitle.Text = String.Empty;
txtFeasibility.Text = String.Empty;
txtCategory.Text = String.Empty;
txtBusCaseStatus.Text = String.Empty;
txtWorkStatus.Text = String.Empty;
txtChargeable.Text = String.Empty;
txtBTProgNo.Text = String.Empty;
txtSponsoringUnit.Text = String.Empty;
txtSponsorName.Text = String.Empty;
txtBTDelCon.Text = String.Empty;
txtBTOneITCon.Text = String.Empty;
txtClientManager.Text = String.Empty;
txtExecManager.Text = String.Empty;
txtESBTLead.Text = String.Empty;
txtAFSLead.Text = String.Empty;
txtKintanaRef.Text = String.Empty;
this.Visible = false;
}
else
{

r1.NextResult();
while (r1.Read())
{
txtWorkRefNo.Text = r1["Work Ref number"].ToString();
txtBusCaseRef.Text = r1["Bus Case Ref"].ToString();
txtDateInitiated.Text = r1["Date Initiated"].ToString();
txtDateAuthorised.Text = r1["Date Authorised"].ToString();
txtDeliveryDate.Text = r1["Delivery Date"].ToString();
txtDateRevised.Text = r1["Revised Date"].ToString();
txtDateClosed.Text = r1["Date Closed"].ToString();
txtProjectTitle.Attributes.Add("value", r1["Project Title"].ToString());
txtFeasibility.Text = r1["Feasibility"].ToString();
txtCategory.Text = r1["Category"].ToString();
txtBusCaseStatus.Text = r1["Bus Case Status"].ToString();
txtWorkStatus.Text = r1["Work Status"].ToString();
txtChargeable.Text = r1["Chargeable"].ToString();
txtBTProgNo.Text = r1["BT Prog No"].ToString();
txtSponsoringUnit.Text = r1["Sponsoring Unit"].ToString();
txtSponsorName.Text = r1["Sponsor Name"].ToString();
txtBTDelCon.Text = r1["BT Del Con"].ToString();
txtBTOneITCon.Text = r1["BT OneIT Con"].ToString();
txtClientManager.Text = r1["Client Manager"].ToString();
txtExecManager.Text = r1["Exec Manager"].ToString();
txtESBTLead.Text = r1["ESBT Lead"].ToString();
txtAFSLead.Text = r1["A&FS Lead"].ToString();
txtKintanaRef.Text = r1["Kintana Ref"].ToString();

//these are the only textboxes who's text property display changes

txtKintanaRef.Enabled = false;
txtBusCaseRef.Enabled = false;
txtWorkRefNo.Enabled = false;

}
}

}


}

again apologies for poor code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top