473,569 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on Registration Check

44 New Member
Hi friends
This is Sweatha. My problem is, I have created the Registration Form with
one LabelBox as Label1
one TextBox as TextBox1 &
one Button as Button1. Then I have generated the random numbers by writing the WebMethod in Web Service as

<WebMethod()> Public Function random1() As Double
Dim Rand As New Random
Dim i As Double
i = Rand.NextDouble
End Function
and calling the WebMethod in Page Load event as

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

Dim obj As New RandomService
Dim value As Double
Dim Random1 As New Random
Label1.Text = Random1.Next

End Sub

In the back end(SQL Server) I have created the table named matching with one field named 'match'.

Now the trouble is

I have to check whether the value entered in the TextBox is equal to that of the one which is in the LabelBox (which is the random one which is automatically generated) and if the value is same then the particular value should be inserted into the (backend) match field in the matching table by using insert query as

If TextBox1.Text = Label1.Text Then

str1 = "Insert into matching values(" & TextBox1.Text & ")"
cmd = New SqlCommand(str1 , con)
cmd.ExecuteNonQ uery()
con.Close()
Response.Write( "Inserted")
End If

My foremost problem is once if I click the button, the page is getting refreshed and the random number in label is changing and the TextBox Values are not getting equal to the LabelBox values & so I cant insert it into the DataBase.
Mar 13 '08 #1
2 989
balame2004
142 New Member
Hi,

In Asp.Net page load event occurs whenever page is getting refreshed. Page is automatically getting refreshed whenever your request is posted back to the server. So page load event is called whenever you click the button since request is posted back to the server if you click a button. This is the reason to lebel text is automatically changing whenever you click the button.


So you have to restrict the page load source code to be executed only when the page is requested for the first time and not for the later server requests. For that you have to use IsPostBack property of Page object. This IsPostBack property would be false when your page is requested for the first time and it would be true when your page is requested later(here whenever you click a button) .

So you have to set the label control only when page is requested for the first time. Please use the below code.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

Dim obj As New RandomService
Dim value As Double

IF(!IsPostBack) 'If isPostBack is false
Dim Random1 As New Random
Label1.Text = Random1.Next
EndIF

End Sub

Regards,
Balaji U
Mar 13 '08 #2
kunal pawar
297 Contributor
Hi Sweatha,
balame2004 gives right solution just write your code into ! isPostback, so ur label is not get changed.
And u will get right value on button click
Mar 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2321
by: Squirrel | last post by:
Given the following piece of code, I was looking for suggestions on how to beautify the portion of the HTML where I jump out of php mode and back in again. The HTML does not have any indenting in order to make the output more readable. However, by not indenting the php code, the php code becomes slightly more difficult to read. Is there a...
4
1409
by: Roland Hall | last post by:
If I wanted to write my own blog application, what functionality should it contain? TIA... -- Roland Hall /* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */
12
2604
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in an embedded environment with multiple processors. I created a policy for classes, which, I had hoped, would automatically register the class with...
6
950
by: scorpion53061 | last post by:
I have a program I have been asked to write and I was wondering if you all might know of a way to control distribution so I am not getting ripped off. It is suppose to go to a college campus and I know kids (I was one once) if I rely on their honor I probably wont get paid at all. It will be distributed by download not a CD though it could...
3
6212
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it has to tell then them its wrong information but currently it takes then to a next page and then tells them its incorrect information. This is tedious...
0
7703
marktang
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...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
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...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
agi2029
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...
0
5222
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...
0
3656
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...
1
2116
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.