C#静态方法访问web前端控件

本文介绍了尝试在C#静态方法中访问Web前端控件时遇到的问题及解决过程,从错误的尝试到最终成功的方法,详细记录了每个步骤的变化和结果。
摘要由CSDN通过智能技术生成

test1:
先说好这个做法是错误的,运行会报错,原因是因为重新定义页面的hp变量里面的所有控件都是空值,无法得到dropdownlist的当前值

using System;
using System.Web.SessionState;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;

public partial class HomePage_Manager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)//!IsPostBack第一次访问该界面,返回true
        //{
        //}
        if (Session["type"] != null)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "themeSearch", "<script>themeSearch('" + Session["type"].ToString() + "')</script>");
        }
    }

    [WebMethod]//js调用时要加上这一句
    public static bool joinBtn()
    {
        bool b = false;
        Theme t = new T
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值