Clicking two times a button is needed to execute javascript code!!!!

csharp , java Albania
  • 12 years ago

    Hi everybody,

    I want some javascript code to execute when I click on a button. On the button click event I execute the following code:

    public void button_Click(object sender, EventArgs evArgs)

    {

       button.Attributes.Add("onclick","parent.parent.functionName('" + param1 + "','" + param2 + "');");

    }

    But the problem that I notice is that I have two click twive this button in order to have the javascript code executed.

    I have tried to put this code on the Page_Load in this cases

    1)if(!Page.IsPostBack)

    button.Attributes.Add("onclick","parent.parent.functionName(' " + param1 + " ',' " + param2 + " ');");

    2)if(Page.IsPostBack)

    button.Attributes.Add("onclick","parent.parent.functionName(' " + param1 + " ',' " + param2 + " ');");

    but in both cases the javascript code doesn't execute at all, and I get a message in the status bar "Done but with errors on page". I have also given values to the parameters passed to javascript function but the message is the same.( The parameters param1 & param2 take their values after the user has filles some textboxes.)

    Can anyone suggest me something.........?

    Thnx anyway

  • 12 years ago

    do you need to have an aspx button? or could you get away with a normal button which fires the event on the OnClick='BLOCKED SCRIPTFire()' , then in the javascript grab the value something like document.form['txtBox1'].value

    Have you tried fireing a basic call without the params like :

    Button.Attributes.Add("onclick","alert('hi');")

  • 12 years ago

    thank u for the ideas you gave to me. I used html control instead of aspx controls.

    For this I didn't use Button.Attributes.Add("onclick"," to execute the javascript code. I used the onclick event of the html control to run the code.

    And yes it works. Big Smile [:D]

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson