Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Jorge Roman

Refresh of page and Onclick event in Form

Recommended Posts

I have a code that use a variable session to control what it must be shown of the page.

The first time that the page is to be loading, a form of data is appears. If the user click in the button submit of

 

the form, the records are save in the database and appear the message "the data had been recorded". If the user

 

refresh the page must be appear another message, for example, "Page expired".

The first time that the page is to be loading the variable session comes with de value 0.

When the user click in the button submit (onclick event) the variable session assumes the value 100.

The problem is:

- when the user refresh the page, the variable session assumes value 100 and the records are to be saved in the

 

database, instead of appearing the message “Page expired”.

What i can do?

 

The code of "page.asp":

 

...<BODY>...	 <% If Session("conta")=0 Then %>		 ...		 <form action="page.asp">			  ...			  <input type="submit" value="SAVE"									onclick='<% Session("conta")=100 %>'>		 </form>	 <% ElseIf Session("conta")=100 Then %>		 ...		 <p>The data had been recorded!</P>		 <% Session("conta")=33 %>	 <% Else %>		 ...		 <p>Page expired!</P>	 <% End If %>...</body>
(Desculpem, mas aproveitei já ter escrito em inglês este Post. Podem responder em Português. Obrigado.)

Compartilhar este post


Link para o post
Compartilhar em outros sites

O seu problema é que o seguinte código

onclick='<% Session("conta")=100 %>'>

não será executado no clicar do botão, e sim no tempo de montagem da tela, pois o evento de clique no browser do usuário não tem nada a ver com a execução server side de se script. Toda vez que você monta o formulário a sessão já fica definida como 100, mesmo que você não pressione nada.

Você tem de trabalhar com parâmetros ou um arquivo intermediário que defina a sessão somente quando o submir ocorrer.

 

got it?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.