Hi,
I want to call JavaScript function from the button_click event. I want fetch data from database first in the click event and then need to pass data to the javascript function for further processing.
Any Help appreciated..............
Thanks,
VIkram
Loading

Christofel Hakim81 reputationPosted May 28, 2010, 2:41 AM EDT
you can use ClientScriptManager to call javascript function on your code behind.
Here i give you a simple example:
ClientScriptManager script = Page.ClientScript;
MyTextBox.Text = "Christofel"; //load your data here
script.RegisterStartupScript (this.GetType(), "Alert","alert(document.getElementById('MyTextBox').value)",true);
//calll your javascript function, then pass the parameter from your asp.net control.
CrishRank #1,487 · 1.1K reputationPosted May 28, 2010, 2:48 AM EDT
protected void cmdSave_Click(object sender, EventArgs e)
{
if ( condition)
{
string script = "";
Page.RegisterClientScriptBlock("ClientScript", script);
}
}
VikramRank #9,295 · 208 reputationPosted May 28, 2010, 2:58 AM EDT
I tried your solution but its not calling desired function. I just test it using following code:
ClientScriptManager script = Page.ClientScript;
script.RegisterStartupScript(this.GetType(), "Alert", "alert('Hello')", true);
Its not showing me Message Box.
Christofel Hakim81 reputationPosted May 28, 2010, 3:12 AM EDT
then you should try this one:
ScriptManager.RegisterStartupScript(this, Page.GetType(), "Alert", "window.alert('Hello');", true);
Jaish MathewsRank #225 · 11K reputationPosted May 28, 2010, 3:34 AM EDT
Check that whether your browser has Javascript enabled.
Tools->InternetOptions->SecurityTab->Internet Icon->Custom Level Button->Scripting Section
Tools->InternetOptions->SecurityTab->Local Intranet Icon->Custom Level Button->Scripting Section
VikramRank #9,295 · 208 reputationPosted May 28, 2010, 3:37 AM EDT
Why Its working this way. I want that button in the Update Panel itself.
Regards,
VIkram
Jaish MathewsRank #225 · 11K reputationPosted May 29, 2010, 9:38 AM EDT
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Alert", "alert('Hello');", true);