回发到同一页面无法正常工作 asp.net

发布于 2024-12-17 11:39:52 字数 2201 浏览 2 评论 0原文

在我的任何特定用户帐户的 user.aspx 页面中,所有其他用户名/图像都显示为数据列表内的链接以及登录的特定用户信息。现在我希望,如果我单击任何其他用户链接,用户信息应该进入同一个 user.aspx 页面。我在页面加载时使用此代码

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Session("UserName") Is Nothing Then
        Response.Redirect("login.aspx")
    Else
        If Not (IsPostBack) Then
            binddata()
            binddata1()
            binddata2()
        End If
    End If
End Sub


     Sub binddata()
    Dim mycommand As New SqlCommand("SELECT * FROM details where id = @id", con)
    mycommand.Parameters.Add("@id", SqlDbType.Int)
    mycommand.Parameters("@id").Value = Convert.ToInt32(Request.QueryString("id"))
    con.Open()
    Data.DataSource = mycommand.ExecuteReader
    Data.DataBind()
    con.Close()

End Sub
Sub binddata1()

    Dim mycommand As New SqlCommand("SELECT * FROM details where id = @id", con)
    mycommand.Parameters.Add("@id", SqlDbType.Int)
    mycommand.Parameters("@id").Value = Convert.ToInt32(Request.QueryString("id"))
    con.Open()
    nameimage.DataSource = mycommand.ExecuteReader
    nameimage.DataBind()
    con.Close()
End Sub
Sub binddata2()

    Dim mycommand As New SqlCommand("SELECT * FROM details ", con)
    con.Open()
   user.DataSource = mycommand.ExecuteReader
    user.DataBind()
    con.Close()
End Sub

,并且此脚本用于数据列表,

  <asp:DataList ID="custom" runat="server" DataKeyField="Name" RepeatColumns="1" >
          <ItemTemplate>
          <div><table>
             <tr><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%#   GetImageURL(Eval("Pic")) %>' PostBackUrl='<%# Eval("id", "user.aspx?id={0}") %>'/></tr>
            <tr><td align="left" valign="top" style="width:90px"><asp:LinkButton ID="name" runat="server" ForeColor="Blue" Text='<%#Container.DataItem("Name")%>'></asp:LinkButton></td></tr>
               </table></div></ItemTemplate>
</asp:DataList>

此代码对于第一次检查/单击工作正常。当我单击其中一个用户时,它会加载该用户的详细信息。但之后,当我单击另一个用户时,它不会加载该用户的详细信息。我想显示:用户登录,然后在他的页面上有其他用户的图像列表。当我单击其中任何一个时,特定的详细信息应该加载到适当的位置。帮我解决这个问题

in my user.aspx page of any particular users account shows all other user names/images as link inside a datalist alongwith the particular users information who is logged in. now i want that if i click any of the other user links the users information should come on the same user.aspx page. i use this code on page load

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Session("UserName") Is Nothing Then
        Response.Redirect("login.aspx")
    Else
        If Not (IsPostBack) Then
            binddata()
            binddata1()
            binddata2()
        End If
    End If
End Sub


     Sub binddata()
    Dim mycommand As New SqlCommand("SELECT * FROM details where id = @id", con)
    mycommand.Parameters.Add("@id", SqlDbType.Int)
    mycommand.Parameters("@id").Value = Convert.ToInt32(Request.QueryString("id"))
    con.Open()
    Data.DataSource = mycommand.ExecuteReader
    Data.DataBind()
    con.Close()

End Sub
Sub binddata1()

    Dim mycommand As New SqlCommand("SELECT * FROM details where id = @id", con)
    mycommand.Parameters.Add("@id", SqlDbType.Int)
    mycommand.Parameters("@id").Value = Convert.ToInt32(Request.QueryString("id"))
    con.Open()
    nameimage.DataSource = mycommand.ExecuteReader
    nameimage.DataBind()
    con.Close()
End Sub
Sub binddata2()

    Dim mycommand As New SqlCommand("SELECT * FROM details ", con)
    con.Open()
   user.DataSource = mycommand.ExecuteReader
    user.DataBind()
    con.Close()
End Sub

and this script for datalist

  <asp:DataList ID="custom" runat="server" DataKeyField="Name" RepeatColumns="1" >
          <ItemTemplate>
          <div><table>
             <tr><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%#   GetImageURL(Eval("Pic")) %>' PostBackUrl='<%# Eval("id", "user.aspx?id={0}") %>'/></tr>
            <tr><td align="left" valign="top" style="width:90px"><asp:LinkButton ID="name" runat="server" ForeColor="Blue" Text='<%#Container.DataItem("Name")%>'></asp:LinkButton></td></tr>
               </table></div></ItemTemplate>
</asp:DataList>

this code is working fine for first check/click. when i click one of the users it load the details of the user . but after that when i click another user it doesnot load the details of that user. i want to show : a user logged in , then there on his page there are list of other users with images. when i click any of them the details of the particular should be load in proper places. help me with this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经大条 2024-12-24 11:39:52

您正在执行数据绑定之前检查第一页加载。删除此检查或检查在其之前触发回发的控件名称。

You are checking for a first page load before perform data binding. Remove this check or check for control name that fire postback before it.

夜空下最亮的亮点 2024-12-24 11:39:52

Yuriy的答案应该有效,但另一种方法是使用 CommandArgument 而不是 PostBackUrl。您需要为 DataList 设置一个事件处理程序 项目命令。 CommandArgument 值将是您的 ID 值。您的事件处理程序将获取该 ID 并将其绑定到您的数据显示。

Yuriy's answer should work but another approach is to use CommandArgument instead of PostBackUrl. You will need to setup an event handler for your DataList ItemCommand. The CommandArgument value will be your ID value. Your event handler will take that ID and bind it to your data display.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文