Button.Attributes.Add refreshing problem

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.
 
G

Grant Merwitz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top