Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Saturday, March 31, 2012

Strange and annoying problem

Even commenting a line in javascript still prompts for an error. If I remove the following line then no error, but again if i put it back, even commented error occurs.

//opener.document.getElementById('<%=TextBox1.ClientID%>').value='akberalikaka';

isn't it strange behavior

Yes it is strange. As far as i am aware of, there are three types of comment you can do in java:

1. Multiple-line :/* and*/

2.One-line comments of C++ style: Begins with // and continue up to the next line break:

3.One-line comments with theHTML comment-opening sequence (<!--). Note that the JavaScript interpreter ignores the closing characters of HTML comments (-->). Consider this example:
<!-- This is treated as a one-line JS comment<!-- It works just like a comment beginning with //<!-- --> This is also a one-line JS comment<!-- --> because JS ignores the closing characters<!-- --> of HTML-style comments

HTML-style comments are not usually found in the middle of JavaScript code. However, it is recommended to use HTML comments for hiding Javascript code from old browsers

Try using this mate


Hi,

//opener.document.getElementById('<%=TextBox1.ClientID%>').value='akberalikaka';

Your comment in javascript doesn't stop<%=TextBox1.ClientID%> since it is asp.net code. So to clear the error you have to remove this code.


You have to comment the aspnet code also

if you are using C#

//opener.document.getElementById('<%/*=TextBox1.ClientID*/%>').value='akberalikaka';

if you are using VB

//opener.document.getElementById('<%'=TextBox1.ClientID'%>').value='akberalikaka';

<%'=TextBox1.ClientID'%> is equivalent to <% Response.Write(TextBox1.ClientID) %>

Thursday, March 22, 2012

Strange IIS6.0/ASP.NET Behaviour (HELP!)

I have a web app that builds a tree from a database. The tree is built on
demand when the user POSTs the page back to the sever. The server maintains
a copy of the current tree in a session object.
This all works fine on the development server but I have a problem on my
live server (IIS6.0 ASP.NET 1.1). When the user posts the page back the
request is not getting to ASP.NET. When tracing is enabled there is no
entry. However the browser is getting an old picture of the tree from a
couple of clicks ago and things start going a bit haywire.
I have set every option I can find within my code to prevent caching
occuring, and I know that no servers along the route a caching because I get
the same problem when I access the app from the server using localhost.
I have read a bit about 2003 and the http.sys cache and believe that my
problem my lie here.
HELP!!
Thanks in anticipation
Mikere:
> I have read a bit about 2003 and the http.sys cache and believe that my
> problem my lie here.
There is a simple way to find out if the problem is with the http.sys cache.
You can disable it entirely.
That way, if the problem continues, you'll know it's not http.sys's fault.
Follow the instructions at http://support.microsoft.com/?id=820129
to create a DWORD value of zero for "UriEnableCache" at this key :
HKEY_LOCAL_MACHINE\System\CurrentControl
Set\Services\HTTP\Parameters
Mind you, use this only for test purposes.
The http.sys cache is important for IIS's performance.
Here's some more background info on http.sys cache which you will find
interesting, since it details the reasons for http.sys *not* caching content
:
http://support.microsoft.com/Default.aspx?id=817445
You might want to try out any of those techniques
to force http.sys to not cache content.
Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
==========================
"Mike Trebilcock" <no@.replies.here> wrote in message
news:dgb3gc$atl$1@.news8.svr.pol.co.uk...
>I have a web app that builds a tree from a database. The tree is built on
> demand when the user POSTs the page back to the sever. The server maintai
ns
> a copy of the current tree in a session object.
> This all works fine on the development server but I have a problem on my
> live server (IIS6.0 ASP.NET 1.1). When the user posts the page back the
> request is not getting to ASP.NET. When tracing is enabled there is no
> entry. However the browser is getting an old picture of the tree from a
> couple of clicks ago and things start going a bit haywire.
> I have set every option I can find within my code to prevent caching
> occuring, and I know that no servers along the route a caching because I g
et
> the same problem when I access the app from the server using localhost.
> I have read a bit about 2003 and the http.sys cache and believe that my
> problem my lie here.
> HELP!!
> Thanks in anticipation
> Mike
>
>

Strange IIS6.0/ASP.NET Behaviour (HELP!)

I have a web app that builds a tree from a database. The tree is built on
demand when the user POSTs the page back to the sever. The server maintains
a copy of the current tree in a session object.

This all works fine on the development server but I have a problem on my
live server (IIS6.0 ASP.NET 1.1). When the user posts the page back the
request is not getting to ASP.NET. When tracing is enabled there is no
entry. However the browser is getting an old picture of the tree from a
couple of clicks ago and things start going a bit haywire.

I have set every option I can find within my code to prevent caching
occuring, and I know that no servers along the route a caching because I get
the same problem when I access the app from the server using localhost.

I have read a bit about 2003 and the http.sys cache and believe that my
problem my lie here.

HELP!!

Thanks in anticipation

Mikere:
> I have read a bit about 2003 and the http.sys cache and believe that my
> problem my lie here.

There is a simple way to find out if the problem is with the http.sys cache.
You can disable it entirely.

That way, if the problem continues, you'll know it's not http.sys's fault.

Follow the instructions at http://support.microsoft.com/?id=820129
to create a DWORD value of zero for "UriEnableCache" at this key :

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Servic es\HTTP\Parameters

Mind you, use this only for test purposes.
The http.sys cache is important for IIS's performance.

Here's some more background info on http.sys cache which you will find
interesting, since it details the reasons for http.sys *not* caching content :

http://support.microsoft.com/Default.aspx?id=817445

You might want to try out any of those techniques
to force http.sys to not cache content.

Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
==========================

"Mike Trebilcock" <no@.replies.here> wrote in message
news:dgb3gc$atl$1@.news8.svr.pol.co.uk...
>I have a web app that builds a tree from a database. The tree is built on
> demand when the user POSTs the page back to the sever. The server maintains
> a copy of the current tree in a session object.
> This all works fine on the development server but I have a problem on my
> live server (IIS6.0 ASP.NET 1.1). When the user posts the page back the
> request is not getting to ASP.NET. When tracing is enabled there is no
> entry. However the browser is getting an old picture of the tree from a
> couple of clicks ago and things start going a bit haywire.
> I have set every option I can find within my code to prevent caching
> occuring, and I know that no servers along the route a caching because I get
> the same problem when I access the app from the server using localhost.
> I have read a bit about 2003 and the http.sys cache and believe that my
> problem my lie here.
> HELP!!
> Thanks in anticipation
> Mike
>

Tuesday, March 13, 2012

strange postback problem

I have a form with a Submit button. The user fills out the form,
clicks the submit button, and then the page posts back to itself.
Every time the page posts back to itself, the "Page_Load" event fires.
So if the user first types the URL of the page in the browser, the
"Page_Load" event fires. Then he hits submit, and the form contents
are posted back, so the "Page_Load" event fires again. The form
appears again (I clear its contents), and he can fill it again, click
submit, and the "Page_Load" event fires again.
I also have a validator control that gives an error message if the user
leaves a field blank. So if the user clicks submit without filling in
a field, the submit code checks "If Page.IsValid()" and puts an error
message on the page. I find that the "Page_Load" event is fired for
this too. In other words, if the form is incorrect and the user clicks
submit, the "Page_Load" event fires, probably just to put the error
message on the page.
Now in the Page_Load event, I want to store the form's contents in a
database. To do that, I have to know why Page_Load is firing. I don't
want to store the form contents if Page.IsPostBack is False, because
that means this is the first time the page is viewed, and the form
hasn't been filled out yet. I also don't want to store the form
contents if there is an error on the page, even though Page_Load is
fired in this case as well.
So I thought the easy way to to this would be to create a Session
variable that tells me if the submit button found the form fields to be
valid. The submit code would look like this:
''
Sub SubmitClick(objSender As Object, objArgs As EventArgs)
If Page.IsValid() Then
LabDiagnostic.Text = "IS VALID"
Session("Valid") = True
Else
LabDiagnostic.Text = "NOT VALID"
Session("Valid") = False
End If
If Session("Valid") = True Then
LabDiagnostic2.Text = "Session('Valid') = True"
Else
LabDiagnostic2.Text = "Session('Valid') = False"
End If
End Sub
Notice that I put in Diagnostics just to be sure the code is working.
The diagnostics do show that it works.
Then in the "Page_Load" event, I test Session("Valid") again:
''''
Sub Page_Load(Source As Object, E As EventArgs)

If Page.IsPostBack Then
If Session("Valid") = True Then
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
Else
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
End If
End If
End Sub
''
But this time the diagnostic gives the opposite result than I expect!
This is so strange that I feel I must be doing something obviously
wrong, but I can't tell what it is.
Here is the entire code of the page, in case someone wants to try it
out:
-- Thanks
-- Marvin

<%@dotnet.itags.org.Page Language="VB" debug="true" %>
<%@dotnet.itags.org.Import NameSpace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %
<HTML>
<HEAD>
<TITLE>Enter Passenger Details</TITLE>
</HEAD
<script language="VB" runat="server">
''''
Sub Page_Load(Source As Object, E As EventArgs)

If Page.IsPostBack Then
If Session("Valid") = True Then
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
Else
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
End If
End If
End Sub
''
Sub SubmitClick(objSender As Object, objArgs As EventArgs)
If Page.IsValid() Then
LabDiagnostic.Text = "IS VALID"
Session("Valid") = True
Else
LabDiagnostic.Text = "NOT VALID"
Session("Valid") = False
End If
If Session("Valid") = True Then
LabDiagnostic2.Text = "Session('Valid') = True"
Else
LabDiagnostic2.Text = "Session('Valid') = False"
End If
End Sub
'' ''
</script
<BODY>
<form METHOD="POST" name="MyForm" runat="server">
<ASP:Label id="LabDiagnostic" runat="server" />
<hr>
<ASP:Label id="LabDiagnostic2" runat="server" />
<hr>
<ASP:Label id="LabDiagnostic3" runat="server" />
<center>
<table border="1">
<tr>
<td align="right">First Name</td>
<td><ASP:Textbox id="FirstName" MaxLength="40" Columns="40"
runat="server" />
<ASP:RequiredFieldValidator id="rfvFirstName" runat="server"
ControlToValidate="FirstName"
ErrorMessage="* You must enter a first name."
Display="dynamic">
*
</ASP:RequiredFieldValidator
</td>
</tr>
<tr><td align="center" colspan="2">
<asp:Button id="MyButton" Text="Submit" runat="server"
OnClick="SubmitClick" />
</td></tr
</table>
</center>
<center>
<table><tr><td>
<ASP:ValidationSummary id="valSummary" runat="server"
HeaderText = "<b>The following errors were found:</b>"
DisplayMode="List" ShowSummary="True" ShowMessageBox="True" />
<!-- normally I have ShowSummary="False" -->
</td></tr></table>
</center>
</form>
</BODY>
</HTMLThe Page_Load event allways fires. When the page loads off it goes, every
time, no exception.

> Now in the Page_Load event, I want to store the form's contents in a
> database. To do that, I have to know why Page_Load is firing. I don't
> want to store the form contents if Page.IsPostBack is False, because
> that means this is the first time the page is viewed, and the form
> hasn't been filled out yet. I also don't want to store the form
> contents if there is an error on the page, even though Page_Load is
> fired in this case as well.
> So I thought the easy way to to this would be to create a Session
> variable that tells me if the submit button found the form fields to be
> valid. The submit code would look like this:

This is not that difficult really. The validators which operate client side
are your first attempt at ensuring that the data is consistant with what you
would like the user to do with it. The validators on the client side will
stop form submission if there criteria is not met.

When the page loads you can test to see if it is a postback and then further
validate from there.

if Page.IsPostback Then

if MyValidationFunction() Then

'Store My Data

Else

litMessage.Text = "Your form has an error on it . . . Blah Blah Blah "

End If

End If

--
Best Regards

The Inimitable Mr Newbie
"COHENMARVIN" <cohenmarvin@.hotmail.com> wrote in message
news:1131192470.623229.323670@.g49g2000cwa.googlegr oups.com...
>I have a form with a Submit button. The user fills out the form,
> clicks the submit button, and then the page posts back to itself.
> Every time the page posts back to itself, the "Page_Load" event fires.
> So if the user first types the URL of the page in the browser, the
> "Page_Load" event fires. Then he hits submit, and the form contents
> are posted back, so the "Page_Load" event fires again. The form
> appears again (I clear its contents), and he can fill it again, click
> submit, and the "Page_Load" event fires again.
> I also have a validator control that gives an error message if the user
> leaves a field blank. So if the user clicks submit without filling in
> a field, the submit code checks "If Page.IsValid()" and puts an error
> message on the page. I find that the "Page_Load" event is fired for
> this too. In other words, if the form is incorrect and the user clicks
> submit, the "Page_Load" event fires, probably just to put the error
> message on the page.
> Now in the Page_Load event, I want to store the form's contents in a
> database. To do that, I have to know why Page_Load is firing. I don't
> want to store the form contents if Page.IsPostBack is False, because
> that means this is the first time the page is viewed, and the form
> hasn't been filled out yet. I also don't want to store the form
> contents if there is an error on the page, even though Page_Load is
> fired in this case as well.
> So I thought the easy way to to this would be to create a Session
> variable that tells me if the submit button found the form fields to be
> valid. The submit code would look like this:
> ''
> Sub SubmitClick(objSender As Object, objArgs As EventArgs)
> If Page.IsValid() Then
> LabDiagnostic.Text = "IS VALID"
> Session("Valid") = True
> Else
> LabDiagnostic.Text = "NOT VALID"
> Session("Valid") = False
> End If
> If Session("Valid") = True Then
> LabDiagnostic2.Text = "Session('Valid') = True"
> Else
> LabDiagnostic2.Text = "Session('Valid') = False"
> End If
> End Sub
> Notice that I put in Diagnostics just to be sure the code is working.
> The diagnostics do show that it works.
> Then in the "Page_Load" event, I test Session("Valid") again:
> ''''
> Sub Page_Load(Source As Object, E As EventArgs)
> If Page.IsPostBack Then
> If Session("Valid") = True Then
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
> Else
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
> End If
> End If
> End Sub
> ''
> But this time the diagnostic gives the opposite result than I expect!
> This is so strange that I feel I must be doing something obviously
> wrong, but I can't tell what it is.
> Here is the entire code of the page, in case someone wants to try it
> out:
> -- Thanks
> -- Marvin
> <%@.Page Language="VB" debug="true" %>
> <%@.Import NameSpace="System.Data" %>
> <%@. Import Namespace="System.Data.SqlClient" %>
> <HTML>
> <HEAD>
> <TITLE>Enter Passenger Details</TITLE>
> </HEAD>
> <script language="VB" runat="server">
> ''''
> Sub Page_Load(Source As Object, E As EventArgs)
> If Page.IsPostBack Then
> If Session("Valid") = True Then
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
> Else
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
> End If
> End If
> End Sub
> ''
> Sub SubmitClick(objSender As Object, objArgs As EventArgs)
> If Page.IsValid() Then
> LabDiagnostic.Text = "IS VALID"
> Session("Valid") = True
> Else
> LabDiagnostic.Text = "NOT VALID"
> Session("Valid") = False
> End If
> If Session("Valid") = True Then
> LabDiagnostic2.Text = "Session('Valid') = True"
> Else
> LabDiagnostic2.Text = "Session('Valid') = False"
> End If
> End Sub
> '' ''
> </script>
> <BODY>
> <form METHOD="POST" name="MyForm" runat="server">
> <ASP:Label id="LabDiagnostic" runat="server" />
> <hr>
> <ASP:Label id="LabDiagnostic2" runat="server" />
> <hr>
> <ASP:Label id="LabDiagnostic3" runat="server" />
> <center>
> <table border="1">
> <tr>
> <td align="right">First Name</td>
> <td><ASP:Textbox id="FirstName" MaxLength="40" Columns="40"
> runat="server" />
> <ASP:RequiredFieldValidator id="rfvFirstName" runat="server"
> ControlToValidate="FirstName"
> ErrorMessage="* You must enter a first name."
> Display="dynamic">
> *
> </ASP:RequiredFieldValidator>
> </td>
> </tr>
> <tr><td align="center" colspan="2">
> <asp:Button id="MyButton" Text="Submit" runat="server"
> OnClick="SubmitClick" />
> </td></tr>
> </table>
> </center>
> <center>
> <table><tr><td>
> <ASP:ValidationSummary id="valSummary" runat="server"
> HeaderText = "<b>The following errors were found:</b>"
> DisplayMode="List" ShowSummary="True" ShowMessageBox="True" />
> <!-- normally I have ShowSummary="False" -->
> </td></tr></table>
> </center>
> </form>
> </BODY>
> </HTML
It seems that my problem was that I assumed the "Submit" button fires
its event before the "Page_Load" event. I had a form with a "Submit"
button, and I thought that when I clicked the "submit" button, the
first thing that would happen was that the code in the "submit" button
event would be executed, and only after that would a "Page_Load" be
executed. But the converse is true, when you click a "submit" button,
the first thing that happens is a "Page_Load", and only after that does
the server execute the code of the "submit" button event.
This is true using the "OnClick" event, the "OnServerClick" event
appears to be radically different, I don't know why.
-- Marvin

strange postback problem

I have a form with a Submit button. The user fills out the form,
clicks the submit button, and then the page posts back to itself.
Every time the page posts back to itself, the "Page_Load" event fires.
So if the user first types the URL of the page in the browser, the
"Page_Load" event fires. Then he hits submit, and the form contents
are posted back, so the "Page_Load" event fires again. The form
appears again (I clear its contents), and he can fill it again, click
submit, and the "Page_Load" event fires again.
I also have a validator control that gives an error message if the user
leaves a field blank. So if the user clicks submit without filling in
a field, the submit code checks "If Page.IsValid()" and puts an error
message on the page. I find that the "Page_Load" event is fired for
this too. In other words, if the form is incorrect and the user clicks
submit, the "Page_Load" event fires, probably just to put the error
message on the page.
Now in the Page_Load event, I want to store the form's contents in a
database. To do that, I have to know why Page_Load is firing. I don't
want to store the form contents if Page.IsPostBack is False, because
that means this is the first time the page is viewed, and the form
hasn't been filled out yet. I also don't want to store the form
contents if there is an error on the page, even though Page_Load is
fired in this case as well.
So I thought the easy way to to this would be to create a Session
variable that tells me if the submit button found the form fields to be
valid. The submit code would look like this:
''
Sub SubmitClick(objSender As Object, objArgs As EventArgs)
If Page.IsValid() Then
LabDiagnostic.Text = "IS VALID"
Session("Valid") = True
Else
LabDiagnostic.Text = "NOT VALID"
Session("Valid") = False
End If
If Session("Valid") = True Then
LabDiagnostic2.Text = "Session('Valid') = True"
Else
LabDiagnostic2.Text = "Session('Valid') = False"
End If
End Sub
Notice that I put in Diagnostics just to be sure the code is working.
The diagnostics do show that it works.
Then in the "Page_Load" event, I test Session("Valid") again:
''''
Sub Page_Load(Source As Object, E As EventArgs)
If Page.IsPostBack Then
If Session("Valid") = True Then
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
Else
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
End If
End If
End Sub
''''
'''
But this time the diagnostic gives the opposite result than I expect!
This is so strange that I feel I must be doing something obviously
wrong, but I can't tell what it is.
Here is the entire code of the page, in case someone wants to try it
out:
-- Thanks
-- Marvin
<%@dotnet.itags.org.Page Language="VB" debug="true" %>
<%@dotnet.itags.org.Import NameSpace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<TITLE>Enter Passenger Details</TITLE>
</HEAD>
<script language="VB" runat="server">
''''
Sub Page_Load(Source As Object, E As EventArgs)
If Page.IsPostBack Then
If Session("Valid") = True Then
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
Else
LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
End If
End If
End Sub
''
Sub SubmitClick(objSender As Object, objArgs As EventArgs)
If Page.IsValid() Then
LabDiagnostic.Text = "IS VALID"
Session("Valid") = True
Else
LabDiagnostic.Text = "NOT VALID"
Session("Valid") = False
End If
If Session("Valid") = True Then
LabDiagnostic2.Text = "Session('Valid') = True"
Else
LabDiagnostic2.Text = "Session('Valid') = False"
End If
End Sub
''''
''
</script>
<BODY>
<form METHOD="POST" name="MyForm" runat="server">
<ASP:Label id="LabDiagnostic" runat="server" />
<hr>
<ASP:Label id="LabDiagnostic2" runat="server" />
<hr>
<ASP:Label id="LabDiagnostic3" runat="server" />
<center>
<table border="1">
<tr>
<td>First Name</td>
<td><ASP:Textbox id="FirstName" MaxLength="40" Columns="40"
runat="server" />
<ASP:RequiredFieldValidator id="rfvFirstName" runat="server"
ControlToValidate="FirstName"
ErrorMessage="* You must enter a first name."
Display="dynamic">
*
</ASP:RequiredFieldValidator>
</td>
</tr>
<tr><td align="center" colspan="2">
<asp:Button id="MyButton" Text="Submit" runat="server"
OnClick="SubmitClick" />
</td></tr>
</table>
</center>
<center>
<table><tr><td>
<ASP:ValidationSummary id="valSummary" runat="server"
HeaderText = "<b>The following errors were found:</b>"
DisplayMode="List" ShowSummary="True" ShowMessageBox="True" />
<!-- normally I have ShowSummary="False" -->
</td></tr></table>
</center>
</form>
</BODY>
</HTML>The Page_Load event allways fires. When the page loads off it goes, every
time, no exception.

> Now in the Page_Load event, I want to store the form's contents in a
> database. To do that, I have to know why Page_Load is firing. I don't
> want to store the form contents if Page.IsPostBack is False, because
> that means this is the first time the page is viewed, and the form
> hasn't been filled out yet. I also don't want to store the form
> contents if there is an error on the page, even though Page_Load is
> fired in this case as well.
> So I thought the easy way to to this would be to create a Session
> variable that tells me if the submit button found the form fields to be
> valid. The submit code would look like this:
This is not that difficult really. The validators which operate client side
are your first attempt at ensuring that the data is consistant with what you
would like the user to do with it. The validators on the client side will
stop form submission if there criteria is not met.
When the page loads you can test to see if it is a postback and then further
validate from there.
if Page.IsPostback Then
if MyValidationFunction() Then
'Store My Data
Else
litMessage.Text = "Your form has an error on it . . . Blah Blah Blah "
End If
End If
Best Regards
The Inimitable Mr Newbie
"COHENMARVIN" <cohenmarvin@.hotmail.com> wrote in message
news:1131192470.623229.323670@.g49g2000cwa.googlegroups.com...
>I have a form with a Submit button. The user fills out the form,
> clicks the submit button, and then the page posts back to itself.
> Every time the page posts back to itself, the "Page_Load" event fires.
> So if the user first types the URL of the page in the browser, the
> "Page_Load" event fires. Then he hits submit, and the form contents
> are posted back, so the "Page_Load" event fires again. The form
> appears again (I clear its contents), and he can fill it again, click
> submit, and the "Page_Load" event fires again.
> I also have a validator control that gives an error message if the user
> leaves a field blank. So if the user clicks submit without filling in
> a field, the submit code checks "If Page.IsValid()" and puts an error
> message on the page. I find that the "Page_Load" event is fired for
> this too. In other words, if the form is incorrect and the user clicks
> submit, the "Page_Load" event fires, probably just to put the error
> message on the page.
> Now in the Page_Load event, I want to store the form's contents in a
> database. To do that, I have to know why Page_Load is firing. I don't
> want to store the form contents if Page.IsPostBack is False, because
> that means this is the first time the page is viewed, and the form
> hasn't been filled out yet. I also don't want to store the form
> contents if there is an error on the page, even though Page_Load is
> fired in this case as well.
> So I thought the easy way to to this would be to create a Session
> variable that tells me if the submit button found the form fields to be
> valid. The submit code would look like this:
> ''
> Sub SubmitClick(objSender As Object, objArgs As EventArgs)
> If Page.IsValid() Then
> LabDiagnostic.Text = "IS VALID"
> Session("Valid") = True
> Else
> LabDiagnostic.Text = "NOT VALID"
> Session("Valid") = False
> End If
> If Session("Valid") = True Then
> LabDiagnostic2.Text = "Session('Valid') = True"
> Else
> LabDiagnostic2.Text = "Session('Valid') = False"
> End If
> End Sub
> Notice that I put in Diagnostics just to be sure the code is working.
> The diagnostics do show that it works.
> Then in the "Page_Load" event, I test Session("Valid") again:
> ''''
> Sub Page_Load(Source As Object, E As EventArgs)
> If Page.IsPostBack Then
> If Session("Valid") = True Then
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
> Else
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
> End If
> End If
> End Sub
> ''''
'''
> But this time the diagnostic gives the opposite result than I expect!
> This is so strange that I feel I must be doing something obviously
> wrong, but I can't tell what it is.
> Here is the entire code of the page, in case someone wants to try it
> out:
> -- Thanks
> -- Marvin
> <%@.Page Language="VB" debug="true" %>
> <%@.Import NameSpace="System.Data" %>
> <%@. Import Namespace="System.Data.SqlClient" %>
> <HTML>
> <HEAD>
> <TITLE>Enter Passenger Details</TITLE>
> </HEAD>
> <script language="VB" runat="server">
> ''''
> Sub Page_Load(Source As Object, E As EventArgs)
> If Page.IsPostBack Then
> If Session("Valid") = True Then
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = True"
> Else
> LabDiagnostic3.Text = "PAGE_LOAD: Session('Valid') = False"
> End If
> End If
> End Sub
> ''
> Sub SubmitClick(objSender As Object, objArgs As EventArgs)
> If Page.IsValid() Then
> LabDiagnostic.Text = "IS VALID"
> Session("Valid") = True
> Else
> LabDiagnostic.Text = "NOT VALID"
> Session("Valid") = False
> End If
> If Session("Valid") = True Then
> LabDiagnostic2.Text = "Session('Valid') = True"
> Else
> LabDiagnostic2.Text = "Session('Valid') = False"
> End If
> End Sub
> ''''
''
> </script>
> <BODY>
> <form METHOD="POST" name="MyForm" runat="server">
> <ASP:Label id="LabDiagnostic" runat="server" />
> <hr>
> <ASP:Label id="LabDiagnostic2" runat="server" />
> <hr>
> <ASP:Label id="LabDiagnostic3" runat="server" />
> <center>
> <table border="1">
> <tr>
> <td>First Name</td>
> <td><ASP:Textbox id="FirstName" MaxLength="40" Columns="40"
> runat="server" />
> <ASP:RequiredFieldValidator id="rfvFirstName" runat="server"
> ControlToValidate="FirstName"
> ErrorMessage="* You must enter a first name."
> Display="dynamic">
> *
> </ASP:RequiredFieldValidator>
> </td>
> </tr>
> <tr><td align="center" colspan="2">
> <asp:Button id="MyButton" Text="Submit" runat="server"
> OnClick="SubmitClick" />
> </td></tr>
> </table>
> </center>
> <center>
> <table><tr><td>
> <ASP:ValidationSummary id="valSummary" runat="server"
> HeaderText = "<b>The following errors were found:</b>"
> DisplayMode="List" ShowSummary="True" ShowMessageBox="True" />
> <!-- normally I have ShowSummary="False" -->
> </td></tr></table>
> </center>
> </form>
> </BODY>
> </HTML>
>
It seems that my problem was that I assumed the "Submit" button fires
its event before the "Page_Load" event. I had a form with a "Submit"
button, and I thought that when I clicked the "submit" button, the
first thing that would happen was that the code in the "submit" button
event would be executed, and only after that would a "Page_Load" be
executed. But the converse is true, when you click a "submit" button,
the first thing that happens is a "Page_Load", and only after that does
the server execute the code of the "submit" button event.
This is true using the "OnClick" event, the "OnServerClick" event
appears to be radically different, I don't know why.
-- Marvin