tonelm54
asked on
Editing Javascript in code
Good afternoon,
My ASP.net application writes some javascript depending on several options selected on a page, and then attaches it to a button, so onClick it fires the javascript.
The issue I have is its a pain clicking the 'Compile' button to attach the Javascript to my button, then having to click the button.
I have through about setting a javascript method to press the button for me 1 second after the page completes load, but it causes 2 problems, 1 I cant seem to guarantee what the button is called during run-time, and the second is the click just causes the page to post back again, and its stuck in a loop.
What I thought about doing is having a javascript segment on the page:-
<script type="test/javascript" id="javaRunMe" runat="server">
</script>
And then adding the javascript inside my code:-
javaRunMe.innerTest = myJavaCode
But this didnt work either, just gave me an error about 'Object reference not set to an instance of an object'
I did also think about writing a Javascript method to see if Button2 had any attributes set, and if it did run them, but again I ran into the problems of I cant garantee what the buttons name is, and I couldnt find any way to test Button2 attributes.
Any ideas?????????
My ASP.net application writes some javascript depending on several options selected on a page, and then attaches it to a button, so onClick it fires the javascript.
The issue I have is its a pain clicking the 'Compile' button to attach the Javascript to my button, then having to click the button.
I have through about setting a javascript method to press the button for me 1 second after the page completes load, but it causes 2 problems, 1 I cant seem to guarantee what the button is called during run-time, and the second is the click just causes the page to post back again, and its stuck in a loop.
What I thought about doing is having a javascript segment on the page:-
<script type="test/javascript" id="javaRunMe" runat="server">
</script>
And then adding the javascript inside my code:-
javaRunMe.innerTest = myJavaCode
But this didnt work either, just gave me an error about 'Object reference not set to an instance of an object'
I did also think about writing a Javascript method to see if Button2 had any attributes set, and if it did run them, but again I ran into the problems of I cant garantee what the buttons name is, and I couldnt find any way to test Button2 attributes.
Any ideas?????????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So I need more detail on what your currently doing and what you're trying to do.
Are you dynamically creating the javascript on the server or is it being done on the client?
You mentioned that previously the user was having to click a button twice? Now are you saying that you don't want the user to have to click a button at all and you would just like to have your code run as soon as the page loads? Give me more of a description of what you need to have happen.
Tell me anything else you think might be helpful for me to understand your situation. The more detail you provide me the easier it will be for me to provide a solution for you.
Are you dynamically creating the javascript on the server or is it being done on the client?
You mentioned that previously the user was having to click a button twice? Now are you saying that you don't want the user to have to click a button at all and you would just like to have your code run as soon as the page loads? Give me more of a description of what you need to have happen.
Tell me anything else you think might be helpful for me to understand your situation. The more detail you provide me the easier it will be for me to provide a solution for you.
ASKER
Ive tried adapting your code to suit my needs:-
Dim sb As New StringBuilder
sb.Append(loadcmd)
ClientScript.RegisterStart
But when it compiles it puts my code outside the script tags:-
<script type="text/javascript">
//<![CDATA[
(function() {var fn = function() {$get("MainContent_Toolkit
</script>
window.open("viewChargeInv
<script type="text/javascript">
//<![CDATA[
Sys.Application.add_init(f
$create(Sys.Extended.UI.Ca
});
Sys.Application.add_init(f
$create(Sys.Extended.UI.Ca
});
//]]>
</script>
BTW- My code is the:-
window.open("viewChargeInv
Any ideas what Im doing wrong?
Thank you