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

2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by namsSoftee
0

After the alert add return false like this :

LinkButton1.Attributes.Add("onclick", " alert('\nYou have already taken this test');return false;")

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...

0

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;");
}
}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.