User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 375,238 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,128 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 452 | Replies: 4
Reply
Join Date: Feb 2008
Posts: 8
Reputation: namsSoftee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
namsSoftee namsSoftee is offline Offline
Newbie Poster

LinkButton1 code fires only on the second click

  #1  
Feb 26th, 2008
Hi Frndz,

My code is like this:





Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
sql = "select LS from Tests_Attended where Emp_ID = " & Session("EmpID")
cmd = New OleDbCommand(sql, con)
ds = cmd.ExecuteReader
If ds.HasRows = True Then
ds.Read()
If ds.Item("LS") = True Then
LinkButton1.Attributes.Add("onclick", " alert('\nYou have already taken this test');") Else
sql = "update Tests_Attended set LS = 1 where Emp_ID= " & Session("EmpID")
cmd = New OleDbCommand(sql, con)
cmd.ExecuteNonQuery()
Server.Transfer("opener1.aspx")
End If
Else
sql = "insert into Tests_Attended values(" & Session("EmpID") & ",1,0,0,0)"
cmd = New OleDbCommand(sql, con)
cmd.ExecuteNonQuery()
Server.Transfer("opener1.aspx")
End If
End Sub




I learnt that If i give the line
LinkButton1.Attributes.Add("onclick", " alert('\nYou have already taken this test');")
in the page_load event, Linkbutton will fire on the first click itself. If so, what am i to give in its place in the above code ? I mean, How am i to invoke the same ?

Regards,
Nams
Last edited by namsSoftee : Feb 26th, 2008 at 11:44 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: istanbul
Posts: 264
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: LinkButton1 code fires only on the second click

  #2  
Feb 27th, 2008
After the alert add return false like this :

LinkButton1.Attributes.Add("onclick", " alert('\nYou have already taken this test');return false;")
Serkan Şendur
MCAD.NET
Reply With Quote  
Join Date: Feb 2008
Posts: 8
Reputation: namsSoftee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
namsSoftee namsSoftee is offline Offline
Newbie Poster

Re: LinkButton1 code fires only on the second click

  #3  
Feb 27th, 2008
HI


Thanks for your reply . Iam new to dotnet. Can you tell me clearly what has to be added where ?
I added
LinkButton1.Attributes.Add("onclick", " alert('\nYou have already taken this test');")
in the page_load event and also i made the change as shown below

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
sql = "select LS from Tests_Attended where Emp_ID = " & Session("EmpID")
cmd = New OleDbCommand(sql, con)
ds = cmd.ExecuteReader
If ds.HasRows = True Then
ds.Read()
If ds.Item("LS") = True Then
LinkButton1.Attributes.Add("onclick", " alert('\nYou have already taken this test');return false;") Else
sql = "update Tests_Attended set LS = 1 where Emp_ID= " & Session("EmpID")
cmd = New OleDbCommand(sql, con)
cmd.ExecuteNonQuery()
Server.Transfer("opener1.aspx")
End If
Else
sql = "insert into Tests_Attended values(" & Session("EmpID") & ",1,0,0,0)"
cmd = New OleDbCommand(sql, con)
cmd.ExecuteNonQuery()
Server.Transfer("opener1.aspx")
End If
End Sub

It works in the first click now but it works both if if-condition passes or fails.

Please modify the code & show me regarding what has to be added where.

Thanks
Nams Here...
Reply With Quote  
Join Date: Jan 2008
Location: istanbul
Posts: 264
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: LinkButton1 code fires only on the second click

  #4  
Feb 27th, 2008
Do the same check in the page load event handler, dont add any script if the check passes, if check fails add the script as i showed earlier.

It will be something like this :

void Page_Load()
{
if(test is taken before)
{
button.attributes.Add("onclick","alert('whatever');return false;");
}
}
Serkan Şendur
MCAD.NET
Reply With Quote  
Join Date: Feb 2008
Posts: 8
Reputation: namsSoftee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
namsSoftee namsSoftee is offline Offline
Newbie Poster

Re: LinkButton1 code fires only on the second click

  #5  
Feb 27th, 2008
Thanks Serkan Şendur .. Its working
Last edited by namsSoftee : Feb 27th, 2008 at 11:15 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC