My label's text isn't changing on page_load asp.net

谁说我不能喝 提交于 2019-12-08 10:42:35

问题


I'm just starting out looking at asp.net. I've got this code that works in VB, but not in asp.

I've put this in the page_load:

Dim db_con As SqlConnection, ssql As String, db_cmd As SqlCommand, rdr As SqlDataReader
    db_con = New SqlConnection("Data Source=myServer;Initial Catalog=processes;User Id=usrID;Password=mypwd;")
    db_cmd = New SqlCommand()
    ssql = "SELECT * FROM command_table_links WHERE command_id = 1"
    db_con.Open()
    db_cmd.Connection = db_con
    db_cmd.CommandText = ssql
    db_cmd.CommandType = Data.CommandType.Text

    rdr = db_cmd.ExecuteReader()
    rdr.Read()
    If rdr.HasRows Then
        lblTest.Text = "It connected"
    Else
        lblTest.Text = "No Connection"
    End If

    rdr.Close()
    db_con.Close()

Any idea why this wouldn't work in asp.net? The issue is that the label is blank. In vb.net as soon as the form is shown, the lable says "It connected".


回答1:


it must be:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



来源:https://stackoverflow.com/questions/6552908/my-labels-text-isnt-changing-on-page-load-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!