在ASP.NET后台代码中加入js代码怎么弄?

在ASP.NET后台代码中加入js代码怎么弄?,第1张

后台调用前台js:ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>a('这个是前台的js')</script>")

这样做,不太现实。

首先,您的按钮是控件来的,随非您将DIv也加入runat="server"

,把DIV显示出来,不过,这种方式,一般都不行,因为,当你把DIV显示出来了,那button按钮就会刷新页面一次,DIV也不会显示出来了。

您可以对button按钮加入OnClientClick事件,写JS显示出来。

我晕~~~~~~ js文件是运行在前台的文件,你在后台怎么可能产生js文件?

下面是在后台代码中生成的随机数字验证码

/// <summary>

/// 生成一个验证码

/// </summary>

using System.Drawing

using System.Drawing.Imaging

private void CreateValidateCode()

{

using(Bitmap bitmap = new Bitmap(80, 24))

{

using(Graphics g = Graphics.FromImage(bitmap))

{

Random rand = new Random()

int code = rand.Next(1000, 9999)

string strcode = code.ToString()

g.DrawString(strcode, new Font("宋体", 18), Brushes.Red, 10, 0)

Session["ValidateCode"] = strcode//使用Session保存数字验证码

ImageButton1.ImageUrl = "source/1.jpg" // 使用source文件夹下面的图片 1.jpg

}

string abspath = System.Web.HttpContext.Current.Server.MapPath(@"source/1.jpg")// 使用source文件夹下面的图片 1.jpg, 作为输出内存中的图片的载体

bitmap.Save(abspath, ImageFormat.Jpeg)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11876732.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存