Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  111] [ 7]  / answers: 1 / hits: 15398  / 16 Years ago, wed, february 18, 2009, 12:00:00

I have a textbox control Super1 in my MasterPage.



I am using javascript to access this control from my content page like this:



<asp:Content ID=ContentPage ContentPlaceHolderID=ContentPlaceHolder1 Runat=Server>
<script type=text/javascript>
function Somethin() {
{
document.forms[0].elements['Super1'].value = sdfsd;
//document.getElementById('<%=Super1.ClientID%>').value = sdfsdf;
}
}
</script>
</asp:Content>


But while page load it says Super1 not found. How can I access Super1?


More From » asp.net

 Answers
13

In your masterpage's onload add this code :



string script = @<script>
function Somethin() {
document.getElementById(' + Super1.ClientID + @').value = 'sdfsd';
}

Somethin();
</script>;
if (!Page.ClientScript.IsClientScriptBlockRegistered(somethin_script_block))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), somethin_script_block, script);
}


this will add your script to the end of the page.



EDIT : I just realized, you use your controls ID directly in your javascript code. this may cause the exception. I update your code to fix it.



I hope this helps.


[#99958] Tuesday, February 10, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ellisw

Total Points: 625
Total Questions: 92
Total Answers: 88

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
ellisw questions
Mon, Aug 23, 21, 00:00, 3 Years ago
Fri, Nov 20, 20, 00:00, 4 Years ago
Sat, Jun 20, 20, 00:00, 4 Years ago
Tue, Apr 21, 20, 00:00, 4 Years ago
;