Link to home
Start Free TrialLog in
Avatar of wsturdev
wsturdevFlag for United States of America

asked on

Dynamically create button and add code to it

I am able to dynamically create a button.  What I cannot figure out is how to add code to it.

I have tried creating a simple handler:
    Protected Sub Go_To_Data_Call()
        Server.Transfer("DataCallForm.aspx")
    End Sub
and then when I create the button, assigning an OnClick attribute:
                    btnGoToDataCall.Attributes.Add("OnClick", "Go_To_Data_Call();")
This gives an error "Microsoft JScript runtime error: object expected"

Then, I have tried to eliminate the handler and just add the OnClick attribute that executes the server transfer directly:
                   btnGoToDataCall.Attributes.Add("OnClick", "Server.Transfer('DataCallForm.aspx');")
This gives an error "Microsoft JScript runtime error: 'Server' is undefined"

What am I doing wrong?
Avatar of Answer_Me
Answer_Me
Flag of India image

where is the code of function Go_To_Data_Call located
Avatar of wsturdev

ASKER

It is in the code behind.
More precisely, it is in the code behind for the page that the button is being created on -- the same place where the code is that adds the attribute.
you should have the method call in your javascript code. and in the javascript code you'll have to write the functionality
ASKER CERTIFIED SOLUTION
Avatar of gnoon
gnoon
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial