Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript/Code-Behind variable not working?

    I have a webpage where I have declared a variable as

    Code:
        <input type="hidden" id="Edits_OK" />
    I set the value of this variable within a Javascript function to either "T" or "F". In my code-behind, I have a btnSubmit_Click() event that calls this Javascript function. In this code-behind event, I also check the value of the "Edits_OK" variable, however, the value is always "". The Javascript function will always put a value in this variable whether it's "T" or "F". I also declare the "Edits_OK" variable within the code-behind as this:

    Code:
        Private Edits_OK As New HiddenField

    Here is the Javascript Function.

    Code:
            function CheckEdits() {
                var msg;
                document.getElementById("Edits_OK").value = 'T';
    
                if (document.getElementById("txtName").value == '') {
                    msg = msg + '\nName';
                    document.getElementById("Edits_OK").value = 'F';
                }
                if (document.getElementById("txtOrganization").value == '') {
                    msg = msg + '\nOrganization';
                    document.getElementById("Edits_OK").value = 'F';
                }
                if (document.getElementById("txtSubject").value == '') {
                    msg = msg + '\nSubject';
                    document.getElementById("Edits_OK").value = 'F';
                }
                if (document.getElementById("txtNote").value == '') {
                    msg = msg + '\nNote';
                    document.getElementById("Edits_OK").value = 'F';
                }
    
                if (document.getElementById("Edits_OK").value == "F") {
                    var msg2;
                    msg2 = "Please provide the following information:\n";
                    error_occurred = true;
                    alert(msg2 + msg);
                }            
            }
    Here is the code-behind Procedure:

    Code:
        Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            Try
                If Edits_OK.Value = "T" Then
                    FormatEmail()
                End If
    
            Catch ex As Exception
                lblErrMsg.Text = "btnSubmit_Click() Event - " & ex.Message
            End Try
        End Sub
    Not sure why the value is always "". Please help!

    Thanks!
    Last edited by blakemckenna; 01-03-2012 at 07:07 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    In my code-behind, I have a btnSubmit_Click() event that calls this Javascript function.
    HUH??? I assume you are talking about ASP.NET code-behind?

    If so, you can't call a javascript function from *ANY* server-side code, ASP.NET or otherwise.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •