如何在前台调用c#后台中声明的方法?
我想在这里调用后台的getpictures()方法
<li><a href="http://www.wxwdesign.cn" target="_blank"><img src="<%=getpictures(1,"tb_leftup_pic","asc")%>" width="443" height="209" alt="展示图片1" /></a></li>
方法如下:
public partial class index : System.Web.UI.Page
{
public string getpictures(int picnum, string dbname, string oderby)
{
if(picnum>0)
{
string picpath = "";
int nums = picnum - 1;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectdb"].ToString());
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select top 1 * from" + dbname + "where id not in(select top"+nums+ "id from"+ dbname +"order by dates" +orderby+")order by dates" +oderby+"",connection);
DataSet dateset = new DataSet();
adapter.Fill(dateset, dbname);
if (dateset.Tables[dbname].Rows.Count > 0)
{
picnum = dateset.Tables[dbname].Rows[0][4].ToString();
}
connection.Close();
}
return picpath;
}
但是现实的运行错误如下:
未声明名称“getpictures”。
请问该如何调用该方法才能正确使用?
------解决方案--------------------
估计你是复制的代码吧?选择一下客户端对象和事件就行了。
前台:<a href="<%=getpictures(1)%>">faskf</a>
后台:public partial class WebUserControl1 : System.Web.UI.UserControl
{
public string getpictures(int picnum)
{
return "http://www.baidu.com";
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
试下肯定没问题的