单击按钮可更改主体上的背景图像,并刷新页面

时间:2019-04-25 19:09:07

标签: c# asp.net

我有一个作业。有一个图像按钮。当我单击“图像”按钮时,体内存在的背景图像必须更改。通过用C#编写代码,我可以通过单击图像按钮来更改背景图像。但是,每次进行后台更改时页面都会刷新。按照我的分配,该页面不应针对每次背景图片的更改而刷新。(供参考,请参阅bing页面,然后单击箭头以更改页面不会刷新的背景图片)

受保护的无效Page_Load(对象发送者,EventArgs e)         {

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        String filenames = "SELECT * FROM [Table]";
        SqlCommand cmd = new SqlCommand(filenames, con);

        cmd.CommandText = "select * from [Table] ";

        con.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        list1 = new ArrayList();
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                list1.Add(reader.GetString(1));
            }
        }
        HiddenField1.Value = ArrayListToString( ref list1);

         string ArrayListToString(ref ArrayList _ArrayList)
        {
            int intCount;
            string strFinal = "";

            for (intCount = 0; intCount <= _ArrayList.Count - 1; intCount++)
            {
                if (intCount > 0)
                {
                    strFinal += "~";
                }

                strFinal += _ArrayList[intCount].ToString();
            }

            return strFinal;
        }

1 个答案:

答案 0 :(得分:0)

C#是服务器端语言。因此,当单击从浏览器到服务器时。然后,服务器返回一个HTML,供您的浏览器页面呈现。因此,刷新页面。 您需要将代码从C#更改为Javascript。 如果您试图从数据库中获取某些东西,则需要使用Javascript进行AJAX调用。

我假设您正在使用ASP.Net。这是一种方法: https://www.aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx