Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I reference an object with a JavaScript literal?

Status
Not open for further replies.

iRead

Programmer
Mar 12, 2004
25
US
In the C# code I want conditionally store reference to an object to a literal executed in a JavaScript .

Example one works:

<script language="JavaScript">
function setFocusIfNeeded()
{
document.all('atMyDropDownList').focus()
}
</script>

<body onload="setFocusIfNeeded();">

Example two is where I want store reference of “document.all('atMyDropDownList').focus()” to ltlScript:

<script language="JavaScript">
function setFocusIfNeeded()
{
<asp:literal id="ltlScript" runat="server" />
}
</script>

<body onload="setFocusIfNeeded();">

My way of thinking one line of C# code should handle this. I have tried many variations with no success. Any help will be greatly appreciated!

Thank you!
iRead
 
If this is for ASP.NET I suggest you look at the following Page members which are specifically designed for this sort of thing...

Page.IsClientScriptBlockRegistered
Page.RegisterClientScriptBlock
Page.RegisterStartupScript

HTH

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
crazyboybert,
I appreciate the input!
Thank you!
iRead
 
This worked for me,
Code:
ltlScript.Text = "document.forms[0].atMyDropDownList.focus();";
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top