javascriptvb.netregisterstartupscript

How to pass 2 parameters through RegisterStartupScript?


I have a javascript function "initialize (latitude, longitude)" and when I click on my button I want to pass the value from my textbox to do something.

Protected Sub btnLat_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim latit As TextBox = formView.FindControl("nr_latitudeTextBox")
    Dim longit As TextBox = formView.FindControl("nr_longitudeTextBox")

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "initialize", "initialize(" & latit.Text, longit.Text & ");", True)

End Sub

But when I try to do this I get the error

Overload resolution failed because no accessible "RegisterStartupScript" accepts this number of arguments.


Solution

  • You have just implemented the code wrongly. Change it to.

    If your initialize function expects string variables then use the code;

    Page.ClientScript.RegisterStartupScript(Me.GetType(), 
    "initialize", "initialize('" & latit.Text & "','" & longit.Text & "');", True)
    

    If initialize expects integers then;

    Page.ClientScript.RegisterStartupScript(Me.GetType(), 
    "initialize", "initialize(" & latit.Text & "," & longit.Text & ");", True)