wsturdev
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("DataCallF orm.aspx")
End Sub
and then when I create the button, assigning an OnClick attribute:
btnGoToDataCall.Attributes .Add("OnCl ick", "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("OnCl ick", "Server.Transfer('DataCall Form.aspx' );")
This gives an error "Microsoft JScript runtime error: 'Server' is undefined"
What am I doing wrong?
I have tried creating a simple handler:
Protected Sub Go_To_Data_Call()
Server.Transfer("DataCallF
End Sub
and then when I create the button, assigning an OnClick attribute:
btnGoToDataCall.Attributes
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
This gives an error "Microsoft JScript runtime error: 'Server' is undefined"
What am I doing wrong?
where is the code of function Go_To_Data_Call located
ASKER
It is in the code behind.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.