ImageButton Problem

ebtihal

Member
Joined
Mar 14, 2011
Messages
21
Programming Experience
Beginner
Hi ..

I creat an ImageButton column, and i want to navigate to another page when i click on the imageButton and send the id with the URL when i navigate.
I try to use OnClientClick() but it doesn't work.
I hope u can help me.

The code is:

VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
dt = New DataTable()
col = New DataColumn("School Name")
dt.Columns.Add(col)
col = New DataColumn("Delete School")
dt.Columns.Add(col)
 
'Get school name to display it in favorite list
con.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
 
sql = String.Format("(select name, school_id from school_site where school_id IN (SELECT school_id FROM favorite_schools WHERE user_name ='{0}')) UNION (select name, school_id from external_school where school_id IN (SELECT school_id FROM favorite_schools WHERE user_name ='{0}'))", Session("user_name"))
 
Dim thisCommand As New SqlCommand(sql, con)
con.Open()
Dim thisReader As SqlDataReader = thisCommand.ExecuteReader()
 
While thisReader.Read()
Row = dt.NewRow()
Row("School Name") = Convert.ToString(thisReader.GetValue(0))
sid = Convert.ToInt32(thisReader.GetValue(1))
AryID.Add(sid)
dt.Rows.Add(Row)
End While
 
Gridview2.DataSource = dt
Gridview2.DataBind()
con.Close()
thisReader.Close()
thisCommand.Dispose()
 
End Sub
 
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview2.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
'to create Hyperlink for "SCHOOL NAME"
Dim Header_Date As DataControlFieldHeaderCell = CType(Me.Gridview2.HeaderRow.Cells(0), DataControlFieldHeaderCell)
If Trim(e.Row.Cells(0).Text) <> " " Then
link = New HyperLink()
link.Text = e.Row.Cells(0).Text
link.Font.Underline = False
link.NavigateUrl = "schoolInfo.aspx?" + AryID.Item(count).ToString()
imgbtn = New ImageButton
imgbtn.ImageUrl = "~/x.gif"
imgbtn.Height = 15
imgbtn.Width = 17
'imgbtn.ResolveUrl("DeleteFavSchool.aspx?" + AryID.Item(count).ToString())
imgbtn.OnClientClick = "document.location.href = = 'DeleteFavSchool.aspx?id='; return false"
 
e.Row.Cells(0).Controls.Add(link)
e.Row.Cells(1).Controls.Add(imgbtn)
count = count + 1
 
End If
End If
End Sub
 
Back
Top