call javascript function on Pageload...asp.net with c#
-
Hi everyone, I am developing a website using asp.net with C#. And I developed a toolbar using javascript like google and yahoo toolbar which is placed in the browser separately. Toolbar has the toolbar id. I need to capture the toolbar id and save into the mysql database during the page load. So that, I put the javascript funcation called myFunc() in the Source file of the page to capture the toolbar id. I need to save the toolbar id into the mysql database and so I applied the coding to insert the toolbarid into the database. When I execute the coding, first of all, the page is loaded, then only the javascript is executed. Therefore, I am unable to get the toolbar id to the variable assigned in the page load. Please help me regarding this. How do I call the javascript function to the page load event. Thanks in Advance, J. Mohan. :-O
J. Mohan
-
Hi everyone, I am developing a website using asp.net with C#. And I developed a toolbar using javascript like google and yahoo toolbar which is placed in the browser separately. Toolbar has the toolbar id. I need to capture the toolbar id and save into the mysql database during the page load. So that, I put the javascript funcation called myFunc() in the Source file of the page to capture the toolbar id. I need to save the toolbar id into the mysql database and so I applied the coding to insert the toolbarid into the database. When I execute the coding, first of all, the page is loaded, then only the javascript is executed. Therefore, I am unable to get the toolbar id to the variable assigned in the page load. Please help me regarding this. How do I call the javascript function to the page load event. Thanks in Advance, J. Mohan. :-O
J. Mohan
-
Hi everyone, I am developing a website using asp.net with C#. And I developed a toolbar using javascript like google and yahoo toolbar which is placed in the browser separately. Toolbar has the toolbar id. I need to capture the toolbar id and save into the mysql database during the page load. So that, I put the javascript funcation called myFunc() in the Source file of the page to capture the toolbar id. I need to save the toolbar id into the mysql database and so I applied the coding to insert the toolbarid into the database. When I execute the coding, first of all, the page is loaded, then only the javascript is executed. Therefore, I am unable to get the toolbar id to the variable assigned in the page load. Please help me regarding this. How do I call the javascript function to the page load event. Thanks in Advance, J. Mohan. :-O
J. Mohan
The other answerer did not understand you, I do not think. you need to buy a book ASP.NET book, you plainly do not understand how it works. Page_Load runs on the server. Then all events run on the server. Then Page_PreRender will run. Only after all these things occur, does script get sent to the client, where javascript code will run. You need to get your toolbar Id in C#, if you want to store it in your DB. OR if you are generating something purely on the client ( bizarre as that may be ), you can send it back to your page with AJAX. That would be really weird tho, you just need to realise no javascript code can hope to run, until all the codebehind C# code has finished running, and the javascript code has therefore been sent to the client, where it runs.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi, Test this one:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "jsFunctionName('Params');", true);
you can execute scripts on page load event using this way
-
The other answerer did not understand you, I do not think. you need to buy a book ASP.NET book, you plainly do not understand how it works. Page_Load runs on the server. Then all events run on the server. Then Page_PreRender will run. Only after all these things occur, does script get sent to the client, where javascript code will run. You need to get your toolbar Id in C#, if you want to store it in your DB. OR if you are generating something purely on the client ( bizarre as that may be ), you can send it back to your page with AJAX. That would be really weird tho, you just need to realise no javascript code can hope to run, until all the codebehind C# code has finished running, and the javascript code has therefore been sent to the client, where it runs.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thanks for your reply, I am a beginner to Asp.net with c#. For all I know ,I took effort to find the solution for the problem mentioned here. I really don't know how to solve it. Therefore, I asked question to you.You expert may encourage the beginners. J. Mohan. :sigh:
J. Mohan
-
Thanks for your reply, I am a beginner to Asp.net with c#. For all I know ,I took effort to find the solution for the problem mentioned here. I really don't know how to solve it. Therefore, I asked question to you.You expert may encourage the beginners. J. Mohan. :sigh:
J. Mohan
cant we call the fun on body tag ? And Here it seems to be hurting when people ask to buy a asp.net book ... but its a fact that everyone needs a book it does not matter whether a expert or beginner Happy Programming
If You win You need not Explain............ But If You Loose You Should not be there to Explain......
-
Thanks for your reply, You have represented "mykey". Should I represent the "mykey" in the javascript. I placed your code. sorry, I doesn't work. Please guide me. Thank You, J. Mohan.
J. Mohan
RegisterStartupScript registers the startup script with the Page object using a type, a key, a script literal, and a Boolean value indicating whether to add script tags.
public void RegisterStartupScript(
Type type,
string key,
string script,
bool addScriptTags
)Parameters type Type: System.Type The type of the startup script to register. key Type: System.String The key of the startup script to register. script Type: System.String The startup script literal to register. addScriptTags Type: System.Boolean A Boolean value indicating whether to add script tags. So, I think you cant represent the "mykey" in the javascript but you can represent script lirtal and you can send your params using that.