Hi everyone,
I have a captcha type of user control that's on a contact page. The problem is that when the user hits Submit it reloads the user control and changes the captcha inside the control before I have a chance to validate against it. This causes the validation to always fail. I was wondering why this happens and what I can do about it. Sorry for being so vague, but this is the best way I can describe the problem.
Thanks to anyone who can help.
Gord
9 1738
Hi Gord,
I don't know what you mean by "captcha" - could you explain?
You can use javascript to validate your controls by firing a function on the forms OnSubmit event like this. - <script type='text/javascript'>
-
function ValidateControls()
-
{
-
// your validation code goes here
-
}
-
</script>
-
<form name='f1' action='page.asp' OnSubmit='return ValidateControls();'>
-
<!-- your controls -->
-
</form>
Have you ever used javascript before?
Dr B
Hey Dr B,
Thanks for your reply. That's true, this could work, but I was hoping for something with code behind.
The term "captcha" means something a user has to do to show they're human. Whenever you're asked to enter the squiggly word you see on forums, etc., that's a captcha. My captcha is simple. It simply reproduce an image a random number of times. The user is to enter the number of times the image appears in order to submit the contact page. The problem is when the user clicks Submit on the contact page, the captcha page reloads, thus regerating the images before I can check if the user entered the correct number.
Any other idea?
Thanks everyone.
Gord
jhardman 3,406
Recognized Expert Specialist
Gord,
I have a doubt from something you said. "Classic" ASP handles this type of thing very different from ASP.NET. Are you using ASP.NET (.aspx file extension) or "classic" ASP (.asp file extension)?
Jared
These are for aspx pages. I'm relatively new to ASP.NET (< year) so the whole sequence of events is still newish to me. I'm from a desktop application background which makes more sense to me. Still getting the hang of this.
Thanks for taking the time to read and reply!
G
jhardman 3,406
Recognized Expert Specialist
Maybe it would make sense then to outline the sequence of events.
1- The form (including the captcha and the textbox the user uses to enter the text) is displayed.
2- The user fills in the blanks
3- The user submits the form to the server
4- The server handles the form - this is where the validation should occur
5- The server returns a response to the user - either a "thank you for submitting" message and continue on to the next page, or a "try again" message or whatever.
My guess is the captcha is being generated at the wrong point, it should really only appear in step 1 (or step 5 in the case of a do-over). It sounds like it is being called when the form is submitted. Does this make sense?
Jared
Plater 7,872
Recognized Expert Expert
Are you checking for IsPostBack in the page_load() event? It will be false on a fresh page load, but will be true when a user clicks an ASPX button(or other control) that calls a "postback".
First of all I have to thank everyone for their comments!
The sequence of events mentioned above was correct. The captcha user control is on the contact page. I don't call it anywhere to load in my code, it just loads on its own (obviously I guess). I added code to the submit button that is on the contact page. The click event basically does the following:
void btnSubmit_Click (Object sender, CommandEventArg s e)
{
if (mycaptcha.Vali dates())
{
//continue with processing the contact page and sending email etc
}
else
{
maycaptcha.Erro rLabel.visible = true;
}
}
The problem is that the captcha control Page_Load fires before the code in my submit click event is hit, even though it's the very first line of code.
I have tried a Page.IsPostback inside my user control but that causes problems. If, in the Page_Load for my user control I do
if (!Page.IsPostba ck)
{
GenerateImages( );
}
else
{
//do nothing
}
then the captcha shows up empty on a postback. I want it to generate a new captcha no matter what, I just want to be able to check it's values before the user control fires it Page_Load.
Sorry for the long message. Hopefully I haven't annoyed everyone.
Thanks in advance for all your time.
Gord
Plater 7,872
Recognized Expert Expert
In the submit button code add the generateImage() line at the end if need be?
I was hoping to keep the captcha control self contained, but this could work. Thanks for the input, I'm going to give it a try!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Alphonse Giambrone |
last post by:
I have a web form with 2 user controls on it (UC1 and UC2).
Each control has a bound datagrid with textboxes in the footer to add a new
row. There are also requiredfieldvalidators in each footer.
When I try to add a new row to UC1 the requiredfieldvalidators for UC2 fire
and therefore the page is not posted.
If I remove one control, everything works fine.
I have 2 questions.
1. How can I get the validators for each control to only...
|
by: Karl |
last post by:
Hi there,
I am using asp.net with c#. I created a web user control "MyControl". When I
click a button, page creates an instance of "MyControl" and loads it at run
time. It is good. And the "MyControl" has a button in it which can do some
magic work. But when I click this button in MyControl, page reloads and
"MyControl" disappears. I know "Mycontrol" is created at run time and when
page reloads, the creating event is not triggered. It is...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage I
know I need to call a function that will save data but I'm not sure exactly
when to call this function.
I've tried two ways and both seem to have 'gotcha's':
|
by: Tim Thomas |
last post by:
Hi,
I am very new to .NET and am in the process of building my first web
application.
I will briefly describe what i am trying to achieve:
I have a system where suppliers register their details, their locations, and
then add themselves to categories. Each category requires additional info
from the suppliers, this additional category info is stored in its own DB
table. a suppliers may add themselves to as many categories as required....
|
by: Mary Kerrigan |
last post by:
I have a user control (menu) with a data list:
<asp:DataList id="MyList" runat="server">
<ItemTemplate>
<asp:hyperlink
cssclass="MenuUnselected"
id="myLink1"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
| |
by: Damon |
last post by:
I am working on a site in which I would like to have two dropdowns that will
allow a user to navigate through the administrative pages of the site. The
first would allow the user to choose the particular site that they would
like to edit. The second would allow the user to select which admin screen
they would like to edit. The second dropdown needs to be populated based on
the selection in the first one. I want to encapsulate these...
|
by: Simon Harvey |
last post by:
Hi everyone,
I'm having a really weird problem with one of my pages. Whenever I hit the
submit button, it reloads the page but another side menu control appears
underneath the original one. This will occur as many times as I hit the
submit button. The thing that I don't understand is that I'm *not* adding
the controls dynamically. The html for the page is very very simple and is
basically the following without the body/head tags etc:
...
|
by: louise raisbeck |
last post by:
I have this scenario (simplified)
function addnewdata () {
check for partial match already in db for information entered by user
if (partialmatch succeeds) {
open new window aspx page (using javascript) with a datagrid of these
partial match records (by doing a sqlcommand using some query string values
taken from opener data entered)
***
}
|
by: Grant Merwitz |
last post by:
Hi
I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.
If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button, but
this script only seems to work for an asp:button and not the
asp:imagebutton.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |