Button.Attributes.Add refreshing problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a popup window, which consists of a TextBox(txtConnectionString) and a
Button(btnOK). And, I would to pass the TextBox.Text to a javascript
function, when Button is clicked. I write the following code in order to do
such thing:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.btnOK.Attributes.Add("onclick", "Done('" &
txtConnectionString.Text & "');")
End Sub

Whereas, after I open the window and change the TextBox.Text, it will pass
the old textbox value to the javascript function, but not the new value. Why
this happen and how to solve?

Please help...thanks.
 
the reason is cause you are hardcoding this value on page load.

So once you change the textbox, you still have that value hardcoded
"txtConnectionString.Text"

Try getting your JavaScript code to read the text value instead of passing
it from the onclick method as your server will not no how the value has
changed client side.

so in you page load:
Me.btnOK.Attributes.Add("onclick", "SomeJavaScriptMethod();")

In Your JavaScript
function SomJavaScriptMethod()
{
alert(document.getElementById("txtConnectionString").value);
}

HTH
 
Back
Top