textbox.value not available yet

R

rodchar

hey all,
i'm running the following:
ScriptManager.RegisterClientScriptBlock in my OnInit event.

well the javascript function that it runs assigns a value to a webserver
textbox control.

after it's finish running this script it control comes back to the
server-side and when i try to inspect the textbox it is still empty, however
when the page finishes loading the correct value appears in the textbox.

is there a certain event i can see the correct value in the code behind
before the page appears?

thanks,
rodchar
 
R

rodchar

thank you for the help Mark,
rod.

Mark Rae said:
What happens is that ASP.NET does all the server-side processing until it's
finished. This results in an HTML stream. This gets streamed down to the
client browser where it gets rendered from top to bottom.

RegisterClientScriptBlock creates a JavaScript block immediately below the
<form runat="server"> tag. At that moment, none of the rest of the form
elements have been created yet. If your JavaScript block needs to reference
any of the form elements, it needs to appear after them in the HTML stream.
For that, you need RegisterStartupScript. This creates the script block just
above the closing </form> tag.

http://it.toolbox.com/blogs/coding-dotnet/registerclientscriptblock-and-registerstartupscript-17321
 
R

rodchar

- Do you want to do this on the first run (in which case this is when you
!IsPostBack) ?
No, I do need it to run on postback.

I have an .aspx page in which all controls are dynamic and i don't know what
the first textbox id will be until runtime.
This is where the javascript function comes into play it determines the
first textbox and places its id in a hidden control where i thought i could
pick it up on server-side.

I''m having to do all this because I have an Ajax UpdatePanel that seems to
overriding any kind of focus i try to set and the very last moment.
I found where you can use ScriptManager.SetFocus and this seems to be the
answer.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top