Access C# Variable in to java Script Function
-
Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.
KnightGuy
-
Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.
KnightGuy
Hi, i'm not really sure what you want to achieve, but if you want to pass the content of the strpicture-variable to a javascript-function during the "onLoad" you could use hiddenfields. Just put strpicture into a hiddenfield of your asp-form and access the value of this field during the "onLoad". Should look like this (client-side):
function onload() {
value = document.getElementById("here goes the hiddenfield-name").value;
ShowPicture(value);
}...
<body onload='javascript:onload()'>...
Hope this helps... Regards Sebastian
-
Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.
KnightGuy
Or You can try this... by using RegisterStartupScript and pass the variable value from the code. public void Page_Load(Object sender, EventArgs e) { // Define the name and type of the client scripts on the page. String yourVariable = "yourVariable"; String csname1 = "PopupScript"; String csname2 = "ButtonClickScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, csname1)) { String cstext1 = "alert('Hello World');"; cs.RegisterStartupScript(cstype, csname1, cstext1, true); } // Check to see if the client script is already registered. if (!cs.IsClientScriptBlockRegistered(cstype, csname2)) { StringBuilder cstext2 = new StringBuilder(); cstext2.Append("script type=text/javascript; function DoClick("); cstext2.Append(yourVariable); cstext2.Append(") {"); cstext2.Append("Form1.Message.value='Text from client script.'} </"); cstext2.Append("script>"); cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false); } } I hope this helps... Cheers vj
-
Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.
KnightGuy
In Java the technology is/was called liveconnect. The best manner to do it now would be to write to the document stream new data or to have Javascript make continuous calls to the server. In your case I would just write the assignment to the file.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.