Posted By: System | Sep 24th, 2007 @ 2:01 AM
page 1 of 1
Comments: 13 | Views: 9728
I have a for loop which places values into three textboxes on my webpage.

I then want to call a javascript funtion before the loop restarts. Is this possible?

So,

 protected void Page_Load(object sender, EventArgs e)
 {

 foreach (GenericBasket.Product itemProduct in Basket1)
 {
            string productName = itemProduct.sName;
            string id = itemProduct.sID;
            float totPrice = itemProduct.TotalPrice;

            TextBox1.Text = productName;
            TextBox2.Text = totPrice.ToString();
            TextBox2.Text = id;
   
            //I want to be able to call my javascript function here
            //myFunction();
}

}
W3bbo
W3bbo
The Master of Baiters
No.

Remember how ASP.NET (and every other web CGI out there) works. It just generates a buffer of text (in this case, XHTML) to send back to the client.

If you want script to execute when a page loads, write a client-side script block which hooks into the window.onload event.

Like so:

<script type="text/ecmascript">
window.onload = loadHandler;

function loadHandler() {

alert("Hello world");

}
</script>
You could render JSON and populate textboxes on the client, int his way you will just call your javascript function at the end or when you want.

Also write code that makes sense if you want us to understand what you want, because that foreach block doesn't have any sense. E.G. what myFunction is supposed to do?
stevo_
stevo_
Human after all
^ Why JSON? because its the latest buzz word? he could just render in fragments of javascript, JSON isn't really a 'fragment' markup, it is great for making a 'oop - class like' environment in javascript however.
stevo_ wrote:
^ Why JSON? because its the latest buzz word? he could just render in fragments of javascript
why not JSON?

var array = [["a", "b", "c"], ["d", "e", "f"], ...];

vs.

var array2 = new Array(new Array("a", "b", "c"), new Array("d", "e", "f"), ...);
stevo_
stevo_
Human after all

You can't call that JSON, thats a mere fragment of javascript that was around even before the terminology of JSON..

Here's what I think of when someone instantly says USE JSON! .. before they even know the context of requirement..

(function() {
  initializer = {
    init: function() {
       ..do minor thing..
    }
  }
});


initializer.init();

vs

..do minor thing..

OK thanks guys. Problem solved.


Here it is nearly 2 years later W3bbo ,The Master of Baiters and I love you. For 2 - 3 days I've been trying to figure out how to do this and it's always something simple once you know how -- window.onload -- huh, well now I will never forget.

Thanks for your time,

friedbrains

W3bbo
W3bbo
The Master of Baiters

....ooookay.

where do I send my invoice for services rendered? Smiley

wow, this thread brings back memories Smiley

 

How did u manage to call the javascript function then I too am having a similar problem

 

W3bbo
W3bbo
The Master of Baiters

Read the thread. You don't.

 

You need to understand and appreciate how ASP.NET works, at a fundamental level, first. Come back when you do.

page 1 of 1
Comments: 13 | Views: 9728
Microsoft Communities