We help IT Professionals succeed at work.
Get Started

How to call a codebehind procedure from javascript

thamilto0410 asked
Last Modified: 2012-06-27
I am new to vb.net.  I am on a deadline therefore I cannot use .net validators.  I am using prebuilt and functioning javascript validation.  I am using the registerclientscriptblock in my codebehind function attached to a button to call the javascript validation and it works perfect.  Once the validation is done I would like to return to the procedure hide one panel and show the other panel that is a review of the form data.  My question is how do I do this from javascript?  If I place the functionality for the panels below the call to the javascript validation function the codebehind does not even halt if the elements are not populated with values it just goes right to the review panel.  My current code is below.

Public Sub close_Onclick(ByVal Src As Object, ByVal E As EventArgs)
        Dim theValue As String
        If Session("role") = "Pl Specialist" Or Session("role") = "Ast Team Captain" Then
            theValue = "validateCU_PS('" & Session("team") & "');"
            theValue = "validateCU_TC('" & Session("team") & "');"
        End If
        Dim sb As New StringBuilder()
        sb.Append("<script language=javascript>")
        ClientScript.RegisterStartupScript(Me.GetType(), "validate", sb.ToString())
            EvalForm.Visible = False
            Dim displayValues1 As New StringBuilder()
            Dim displayValues2 As New StringBuilder()
            Dim thecols As String = ""
            Dim thevals As String = ""
            Dim postedValues As NameValueCollection = Request.Form
            Dim nextkey As String = ""
            For i As Integer = 0 To postedValues.AllKeys.Length - 1
                nextkey = postedValues.AllKeys(i)
                If nextkey.Substring(0, 2) <> "__" Then
                    If nextkey <> "senditback" And nextkey <> "closecase" And nextkey <> "sbmtForm" Then
                        If postedValues(i) <> "Select" And postedValues(i) <> "Select One" Then
                            If postedValues(i).ToString = "" Then
                            End If
                        End If
                    End If
                End If

            Session("evalcolumns") = Left(Trim(displayValues1.ToString), Len(displayValues1.ToString) - 1)
            Session("evalvalues") = Left(Trim(displayValues2.ToString), Len(displayValues2.ToString) - 1)
            thecolumns.Text = displayValues1.ToString()
            thevalues.Text = displayValues2.ToString()
            ReviewEval.Visible = True
    End Sub
Watch Question
Most Valuable Expert 2012
Top Expert 2008
This problem has been solved!
Unlock 3 Answers and 17 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE