473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Question on Registration Check

44
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.EventArgs) 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.ExecuteNonQuery()
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 975
balame2004
142 100+
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.EventArgs) 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 100+
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
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...
4
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...
12
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...
6
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...
3
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.