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
Jaish MathewsPosted May 29, 2010, 1:38 PM
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Alert", "alert('Hello');", true);
VikramPosted May 28, 2010, 7:37 AM
Why Its working this way. I want that button in the Update Panel itself.
Regards,
VIkram
Jaish MathewsPosted May 28, 2010, 7:34 AM
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
Christofel HakimPosted May 28, 2010, 7:12 AM
then you should try this one:
ScriptManager.RegisterStartupScript(this, Page.GetType(), "Alert", "window.alert('Hello');", true);
VikramPosted May 28, 2010, 6:58 AM
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.
CrishPosted May 28, 2010, 6:48 AM
protected void cmdSave_Click(object sender, EventArgs e)
{
if ( condition)
{
string script = "";
Page.RegisterClientScriptBlock("ClientScript", script);
}
}
Christofel HakimPosted May 28, 2010, 6:41 AM
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.