Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi guys
I have code like below and I have declared the getscript function to open the display.aspx page as a window. The problem is when I click on the button it doesn't fires the click event of the button and do the rest. I want to fire the click event of the Button1. How can I achieve it?
Note : It works some times

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    Dim _scriptJS1 As String = GetScript("display.aspx", "NascarMap", True, False, False, False, False, False, False, False)
    Button1.Attributes.Add("onclick", _scriptJS1)
Updated 12-Nov-13 4:56am
Ganesh KP 12-Nov-13 12:05pm    
Hi Reji, can u try this way of assigning a click event dynamically
button.Click += Your_Method;
public void Your_Method(Object sender, RoutedEventArgs e)
{ //Rest of the code goes here where u can call the page to open}

try this way, I think it might works and if it does n't work, let us know
Reji Ab 13-Nov-13 11:48am    
Thank you Ganesh, Where do I put your code. I couldn't use it errors
Er Daljeet Singh 14-Nov-13 5:39am    
Put this code on Page_Load Event

please try this

change the causes validation property of that particular button

Causes Validation = "false"
Share this answer
Reji Ab 14-Nov-13 7:52am    
Thanks Chauhan, that works absolutely fine
dmsWebDev 15-Dec-14 18:23pm    
Thank you!

This solved the problem for me. I had added validation summary control then removed it and forgot to reset causes validiong to false on my click control

I solved myself, I need to put return true as below to force postback

Button1.Attributes.Add("onclick", _scriptJS1 + ";  return true;")
Share this answer
If it works sometimes, then it is possible that the window is already opened in the background (from the first time you open) and opening it again will just load the page but without bringing it to the front.
Share this answer
Reji Ab 13-Nov-13 11:55am    
Thank you for your reply. It doesn't work even if there is no window already opened in the background
Alexandru Lungu 13-Nov-13 19:23pm    
Then, what do you mean by "It works some times"?
Reji Ab 14-Nov-13 5:35am    
I solved myself, I need to put return true as below to force postback
Button1.Attributes.Add("onclick", _scriptJS1 + "; return true;")
set postbackurl property of button as below

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900