Hello there! I am just starting out with web programming and I've hit a little bump in the road. Here's my current situation:
- The user lands on a page and clicks on the "Upload document" button.
- The document gets uploaded to the server, is processed, and the page displays the new information obtained from the file.
- The user then has the option to click on a "PERFORM" button which triggers a server method.
- Within the server method, there is an if statement. If it evaluates to true, everything is fine. However, if it's false, a confirmation dialog is presented to the user.
- If the user selects NO, the process comes to a halt.
- If the user chooses YES, a different server method is executed, and then we loop back to step 4.
I have successfully completed points 1, 2, and 3; however, I'm currently stuck on the 4th point...
I believe this difficulty stems from not having a full grasp on how servers and clients interact. While I understand that direct JavaScript to C# calls (and vice versa) are not possible, techniques like Ajax provide ways to achieve this... though I still find them a bit unclear at the moment.
Let me share a snippet of my code for reference:
UploadDoc.aspx
<script type="text/javascript" language="javascript">
function ConfirmDialog() {
if (confirm("You are new. Would you like to sign-in?") == true) {
// call server method
}
}
</script>
...
<asp:Button ID="btnUpload" runat="server" Text="UPLOAD DOC" OnClick="btnUpload_Click" />
UploadDoc.aspx.cs
// ...
private bool btnUpload_Click(List<MyStuff> myList)
{
List<MyStuff> vList = new List<MyStuff>();
bool up = Upload(vList);
// ...
}
private bool Upload(List<MyStuff> myList)
{
bool registered;
// ... other stuffs...
if (registered == true)
{
// do things...
}
else
{
// At this point, the confirm dialog should be displayed.
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "ConfirmDialog()", true);
}
}