To add a function or JavaScript code inside an UpdatePanel, we simply register the script block, you can do it in any event hand, according to our need, it could be in the Page_Load as could also be in the event of a ButtonClick button.
For example:
protected void Page_Load(object sender, EventArgs e)
{
// Register the script before assigning the function to the OnClientClick event of the button, there should be a button DevExpress
ScriptManager.RegisterStartupScript(this, this.GetType(), "theScriptKey", "MyFunction function (x, y) {alert (x); alert (y);}", true);
}
What matters is that prior to the assignment of the call to the button event, we must ensure register block caught JavaScript.
To run this function from some event, for example from a button click event, we assign the call to the function des follows:
protected void Button1_Click(object sender, EventArgs e)
{
// Assign the variable eye if a string must incluier single quotes'
string param1 = "'added to test alert button from a method with step parametos'";
// Assign the variable 2nd-, eye if a string must incluier single quotes'
string param2 = "'Mostamos the second parameter passed to the JavaScript function'";
// Assign to OnClientClick event of the button to the function llamadao with paramstros Ticket
Button1.OnClientClick = "MyFunction (" + param1 + "," + param2 + ")";
}
See also
0 comentarios:
Post a Comment