UPDATE:
It seems that the issue lies in the fact that an ASP:GridView has an OnDataBound() event in the code-behind, but the corresponding HTML table does not. To address this, I need to attach the event to JavaScript. This realization is causing some difficulty for me in resolving this particular problem. Back to square one.
Transitioning from desktop development with WinForms and VB.NET to ASP.NET has been quite a challenge for me. The concepts of DOM, JavaScript, Session State, and other web development aspects have stretched my mind. Despite conducting extensive research, including watching hours of videos and reading hundreds of pages on "Intro to ASP.NET", I still encounter hurdles with what should be simple issues.
Essentially, my current predicament can be summed up as follows:
- I have a page where the user initiates a lengthy process.
- This process can take several minutes, so I want to provide feedback to the user indicating ongoing activity.
- Upon completion of the process, there are two scenarios:
a. Results to display in a GridView
b. No results to display - If there are results, I need to showcase them.
- If there are no results, I want to show a label stating "No results to display" to the user.
What's currently functioning:
- The basic page allows users to select start and end dates to initiate the process.
- The processing logic using LINQ-to-SQL, created for a desktop application, works well.
- An UpdatePanel on the page shows a label and an animated gif to indicate ongoing activity.
- If results are available, they are correctly displayed in the GridView.
Challenges faced:
I would like to implement a progress bar to visually represent the progress made towards completion instead of relying on a continuously animating gif. While I can calculate the progress value easily, transferring this value from the server to the webpage poses a challenge.
Figuring out how to trigger an event to reveal the label is proving difficult. The long process runs within a button's click event handler, where I execute custom code and generate a DataTable saved as a session variable. After assigning it as the DataSource for the GridView and calling GridView.DataBind(), attempts to hide/reveal the label based on DataTable content yield no visible changes.
Solving Problem #2 is crucial for preparing this website for deployment. It likely involves a JavaScript solution, which I've attempted, but my efforts feel more like guesswork without a clear understanding of the optimal solution.
Below is the label I aim to selectively reveal/make visible:
<tr>
<td colspan="2" align="center">
<h2><asp:Label runat="server" ID="lblNoMissing" Text="No Missing Documentation Found" Visible="false"></asp:Label></h2>
</td>
</tr>
Here is a JavaScript function I am experimenting with:
<script type="text/javascript">
function databound() {
var gridViewID = '<%=_gridView1.ClientID%>';
var labelID = '<%=lblNoMissing.ClientID%>';
var gridView = document.getElementById(gridViewID);
if (gridView.rows.length > 0) {
$get(labelID).style.visibility = "false";
} else {
$get(labelID).style.visibility = "true";
}
}
</script>
Error Encountered: Failure message reads: (databound not a member of Default.aspx)
<asp:GridView ID="_gridView1" runat="server"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="Horizontal" PageSize="20" OnDataBound="databound();">
// Rest of GridView definition removed
</asp:GridView>
What step am I missing here?
Your assistance is greatly appreciated!