•
•
•
•
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
![]() |
•
•
Join Date: Feb 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
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
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.
•
•
Join Date: Feb 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
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...
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...
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;");
}
}
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
MCAD.NET
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
access activation api blogger blogging blogs business code combo cross-browser javascript menu with few lines of code cyber-squatting dani daniweb data debugging development domains dreamweaver dropdownlist equivalent code of messagebox in asp.net gdata google gpl html innovation key linux microsoft module net news openbsd pay-per-click product programming reuse rss security serial source strider tags trademark typo-squatting vista web wysiwyg xml
- Previous Thread: Manual Sort with GridView control
- Next Thread: Detailsview not visible


Linear Mode