I wanted to know if anyone can help me. What I am trying to do is have a page load, and on the load, the page checks for a username and password. If the user has never visited the page, the page will prompt the user to enter their password. Once the user hits
submit, the page calls a proc and stores the info in a database. What I am trying to do, is after the page has stored the info in the database, I want the code behind to simulate a button click event so it will fire the click event and run a javascript function.
I know how to add the attribute to the button, what I don't know is how to simulate a click event after the user has posted back to the page. I don't want the user to have to click the button twice. Anyone have any ideas? By the way, I can not use an HTTPWebrequest
because I can not post the next page I am trying to go to.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1_Click(sender, e)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("All Right")
End Sub
This posting is provided "AS IS" with no warranties, and confers no rights.
Thank you for your reply. I did test what you posted and it does work, but I guess I didn't explain everything that I needed. On the page load, provided an if statement is true, I add and attribute 'onclick' to the button, so that when I need to click it, it
calls a javascript function on the html page. This is what I am trying to do. I want the click even to fire the onclick event attribute that I just assigned to the button. I can not get the attribute to fire correctly. btnSubmit.Attributes.Add("OnClick","
return nextpage();"); btnSubmit_Click(sender, e);
Sounds like you're wanting to trigger a client-side click from the server-side: Where you're trying btnSubmit_Click put: Page.RegisterStartupScript("ClickScript", "<script language='javascript'>document.getElementById('" + btnSubmit.ClientID + "').click();</script>");
This will drop the code on the client-side to trigger the click event of your submit button.
Thank you very much. The startupscript worked like a champ. I was completely unware of that functionality. Thanks to Jim to for helping me. I hope I can return the favor in the future:)
dobe32
Member
125 Points
25 Posts
fire click event from code behind
Aug 11, 2004 06:42 PM|LINK
JimmyM
Star
8796 Points
1671 Posts
Re: fire click event from code behind
Aug 11, 2004 07:40 PM|LINK
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button1_Click(sender, e) End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Write("All Right") End Subdobe32
Member
125 Points
25 Posts
Re: fire click event from code behind
Aug 11, 2004 08:43 PM|LINK
stiletto
All-Star
16995 Points
3304 Posts
Re: fire click event from code behind
Aug 12, 2004 01:28 AM|LINK
dobe32
Member
125 Points
25 Posts
Re: fire click event from code behind
Aug 12, 2004 08:18 PM|LINK