Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:48:22+00:00 2026-06-13T05:48:22+00:00

I’ve got a simple ASP.NET GridView that is databound to a view on our

  • 0

I’ve got a simple ASP.NET GridView that is databound to a view on our database.

When a row is selected, the Request is added to the Session variables and to the Request ID TextBox. The TextBox’s TextChanged event and the PostBack event both verify this as I step through the process, but the values are not displayed on the website afterwards.

The code is posted on .NET Pad here: http://dotnetpad.net/ViewPaste/TJp2pldPkk6poP3cVzRlHQ

Note: I have also tried commenting out all of the code in the Page_Load for the PostBack event, but this did not solve my problem.

What could make this work?

Code:

<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<script runat="server">

  protected void Page_Load(object sender, EventArgs e) {
    if (IsPostBack) {
      //int nDDL = GetInteger(Session[ddlSelector.ID]);
      //if (nDDL == ddlSelector.SelectedIndex) {
      //  int reqID = GetInteger(Session[txtRequestID.ID]);
      //  if ((0 < reqID) && (reqID.ToString() != txtRequestID.Text)) {
      //    string strEmp = IsNumeric(Session[txtEmployee.ID]) ? GetText(Session[txtEmployee.ID]) : null;
      //    txtRequestID.Text = reqID.ToString();
      //    txtEmployee.Text = strEmp;
      //    if (nDDL != ddlChangeTo.SelectedIndex) {
      //      ddlChangeTo.SelectedIndex = nDDL;
      //    }
      //  }
      //}
    } else {
      Session[ddlSelector.ID] = null;
      Session[txtRequestID.ID] = null;
      Session[txtEmployee.ID] = null;
      txtRequestID.Text = null;
      txtEmployee.Text = null;
      txtMTF.Text = null;
      btnOK.Visible = (0 < GetInteger(txtRequestID.Text));
    }
  }

  private void ErrorMessage(string message) {
    Response.Write(string.Format("<font color=\"Red\"><b>{0}</b></font>", message));
  }

  protected void GridViewRow_Selected(object sender, EventArgs e) {
    var row = GridView1.SelectedRow;
    if (row != null) {
      var reqIdCell = row.Cells[1];
      if (reqIdCell != null) {
        int reqID = GetInteger(reqIdCell.Text);
        if (0 < reqID) {
          Session[ddlSelector.ID] = ddlSelector.SelectedIndex;
          Session[txtRequestID.ID] = reqID;
          txtRequestID.Text = reqID.ToString();
          txtEmployee.Text = null;
          btnOK.Visible = true;
        }
      }
    }
  }

  protected void Submit_Click(object sender, EventArgs e) {
    int reqID = GetInteger(Session[txtRequestID.ID]);
    if (0 < reqID) {
      ErrorMessage("Success!");
    } else {
      ErrorMessage("Unrecognised Request ID.");
      txtRequestID.Focus();
    }
  }

  protected void TextBox_TextChanged(object sender, EventArgs e) {
    if (sender is TextBox) {
      TextBox tbx = (TextBox)sender;
      if (tbx.ID == txtRequestID.ID) {
        int reqID = GetInteger(txtRequestID.Text.Trim());
        int reqI2 = GetInteger(Session[txtRequestID.ID]);
        if (0 < reqID) {
          Session[txtRequestID.ID] = reqID;
        } else {
          txtRequestID.Text = null;
        }
        if (0 < reqI2) {
          txtRequestID.Text = reqI2.ToString();
        }
      } else if (tbx.ID == txtEmployee.ID) {
        string empNum = txtEmployee.Text.Trim();
        if (IsNumeric(empNum)) {
          Session[txtEmployee.ID] = empNum;
        } else {
          txtEmployee.Text = null;
        }
      }
    } else if (sender is DropDownList) {
      DropDownList ddl = (DropDownList)sender;
      if (ddl.ID == ddlSelector.ID) {
        Session[ddlSelector.ID] = ddlSelector.SelectedIndex;
        Session[txtRequestID.ID] = null;
        Session[txtEmployee.ID] = null;
      }
    }
  }

  protected void Tick_Tock(object sender, EventArgs e) {
    GridView1.DataBind();
  }

  private static int GetInteger(object value) {
    int result = -1;
    if (HasValue(value)) {
      try {
        result = (int)value;
      } catch {
        result = -1;
      }
    }
    if (result == -1) {
      result = 0; // errors could occur if I try indexing things with negative numbers
      string text = GetText(value);
      if (!String.IsNullOrEmpty(text)) {
        int.TryParse(text.Trim(), out result);
      }
    }
    return result;
  }

  private static string GetText(object value) {
    if (HasValue(value)) {
      return value.ToString().Trim();
    }
    return null;
  }

  private static bool HasValue(object item) {
    if ((item != null) && (item != DBNull.Value)) {
      return !String.IsNullOrEmpty(item.ToString().Trim());
    }
    return false;
  }

  private static bool IsNumeric(object input) {
    if (input == null) return false;
    string text = input.ToString();
    if (!String.IsNullOrEmpty(text.Trim())) {
      foreach (char c in text.ToCharArray()) {
        if (char.IsLetter(c)) return false;
      }
    }
    return true;
  }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <asp:SqlDataSource ID="productionDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CPWEB_PRODUCTION %>" SelectCommand="SELECT [RequestID], [Employee], [DateStamp], [Line], [PartNo], [Workorder], [Qty], [MTF], [Status] FROM [vwRequestsEx] WHERE ([Status] = @Status)"><SelectParameters>
          <asp:ControlParameter ControlID="ddlSelector" Name="Status" PropertyName="SelectedValue" Type="String" />
        </SelectParameters></asp:SqlDataSource>
      <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
      <table style="width: 90%">
        <tr>
          <td>Display:<br /><asp:DropDownList ID="ddlSelector" runat="server" DataSourceID="productionStatus2" DataTextField="Description" DataValueField="Description" OnSelectedIndexChanged="TextBox_TextChanged"></asp:DropDownList>
            <asp:SqlDataSource ID="productionStatus2" runat="server" ConnectionString="<%$ ConnectionStrings:CPWEB_PRODUCTION %>" SelectCommand="SELECT [ID], [Description] FROM [Status]"></asp:SqlDataSource>
          </td>
          <td>RequestID:<br /><asp:TextBox ID="txtRequestID" runat="server" OnTextChanged="TextBox_TextChanged" AutoCompleteType="Disabled" /></td>
          <td>Employee:<br /><asp:TextBox ID="txtEmployee" runat="server" OnTextChanged="TextBox_TextChanged" AutoCompleteType="Disabled" /></td>
          <td>MTF:<br /><asp:TextBox ID="txtMTF" runat="server" OnTextChanged="TextBox_TextChanged" AutoCompleteType="Disabled" /></td>
          <td style="width: 110px;">Change To:<br /><asp:DropDownList ID="ddlChangeTo" runat="server" DataSourceID="productionStatus3" DataTextField="Description" DataValueField="Description"></asp:DropDownList>
            <asp:SqlDataSource ID="productionStatus3" runat="server" ConnectionString="<%$ ConnectionStrings:CPWEB_PRODUCTION %>" SelectCommand="SELECT [Description] FROM [Status] WHERE ([Description] &lt;&gt; @Description)"><SelectParameters>
              <asp:ControlParameter ControlID="ddlSelector" Name="Description" PropertyName="SelectedValue" Type="String" />
            </SelectParameters></asp:SqlDataSource>
          </td>
          <td><br />
            <asp:Button ID="btnOK" runat="server" Text="Submit" OnClick="Submit_Click" Width="75px" /></td>
        </tr>
        <tr>
          <td class="nowrap" colspan="6">
            <asp:Timer ID="Timer1" OnTick="Tick_Tock" runat="server" Interval="30000"></asp:Timer>
            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
              <Triggers><asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /></Triggers>
              <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateSelectButton="True" CellPadding="1" DataSourceID="productionDataSource2" EmptyDataText="No Records to Display" Font-Size="Small" ForeColor="#333333" OnSelectedIndexChanged="GridViewRow_Selected" ShowHeaderWhenEmpty="True" HorizontalAlign="Left" RowHeaderColumn="RequestID" Width="95%">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
              <asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" />
              <asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee" />
              <asp:BoundField DataField="DateStamp" HeaderText="DateStamp" SortExpression="DateStamp" />
              <asp:BoundField DataField="Line" HeaderText="Line" SortExpression="Line" />
              <asp:BoundField DataField="PartNo" HeaderText="PartNo" SortExpression="PartNo" />
              <asp:BoundField DataField="Workorder" HeaderText="Workorder" SortExpression="Workorder" />
              <asp:BoundField DataField="Qty" HeaderText="Qty" SortExpression="Qty" />
              <asp:BoundField DataField="MTF" HeaderText="MTF" SortExpression="MTF" />
              <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left" Wrap="False" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2"></SortedAscendingCellStyle><SortedAscendingHeaderStyle BackColor="#506C8C"></SortedAscendingHeaderStyle><SortedDescendingCellStyle BackColor="#FFFDF8"></SortedDescendingCellStyle><SortedDescendingHeaderStyle BackColor="#6F8DAE"></SortedDescendingHeaderStyle></asp:GridView></ContentTemplate></asp:UpdatePanel></td>
        </tr>
      </table>
    </div>
  </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:48:23+00:00Added an answer on June 13, 2026 at 5:48 am

    Posting the actual portion you have problem with would get you better answer instead of this.

    You don’t need all the else portion, just do this

      protected void Page_Load(object sender, EventArgs e)
      {
        if (!Page.IsPostBack)
        {
             //code to execute here only when an action is taken by the user
             //and not affected by PostBack
        }
    
        //these codes should be affected by PostBack
     }
    

    Hope it helps!

    Update

    I believe your UpdatePanel is what is causing the problem. Removing the UpdatePanel, things look OK.

    The reason controls at the top were not being updated is because they are not in the UpdatePanel, any changes you make from codebehind by controls in the UpdatePanel (e.g. PostBack by the “Select” link) will never get to them.

    One solution is to also include those controls at the top, e.g. RequestID textbox in the UpdatePanel.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.