Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

raising onclick events before postback? should be easy

Status
Not open for further replies.

whykeepderegingme

Programmer
May 17, 2005
6
CA
Hey,

I want to run a button click event BEFORE postback. Logical, yes. Useful, yes, on pretty much every page of my web app.

It makes perfect sense to me, my logic does:

You have a page with 2 panels on it. The first, "Language" has a few buttons on it, for language selection. The second, "Login" has login textboxes.

Initially, "Language" is visible. So you click a language button. That button fires an event, which sets language cookie, and sets "Login" panel to visible and "Language" panel to hidden.

Then, postback occurs. Lets say Page_Load checks if cookie exists to change panels, because I don't trust that you can change panels in button event. The cookie exists, so the "Login" panel is made visible. All is well with the world.


Alas, reality is nothing like my logical fantasy, here is what is happening:

You click the button. Immediately, postback occurs, says "hey, there is no cookie", so display the same page again. Then click event occurs, and creates the cookie.

So I have to click said button AGAIN, and only then does postback say "oh, there is a cookie".

Seriously, am I missing something here?

 
I think you are looking at the design of the pages incorrectly. You essentially have two pages here but you have chosen to try and implement them in one. What happens if you looked at it this way:

1) Go to language.aspx and pick a language (in the button click event here you add your cookie and redirect to login.aspx)
2) In the page load event of login.aspx you check for the cookie (that now exists) and do whatever you need to do.

Doing it like this makes a lot more sense to me.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
well, i got it to work, by changing panels in the Click event, because this causes another postback, and then I don't do anything in page_load, other than set languagePanel.Visible to true if IsPostBack is false.

I have made the login system based on panels because I have had a heinous time trying to implement login popups, so instead, here is what I plan to do:

Each page has 2 panels, one is the page itself, the other is the language/login user control. Initially when you go to a page, it will check for the appropriate cookies, and should they fail to be found, the user control panel will be displayed. I'm hoping I can maintain the form data, so when they have eventually logged back in, on Page_Load the actual page panel will be displayed, with the appropriate data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top