JavaScriptÖзÃÎÊC#±äÁ¿¼°·½·¨
1.ÈçºÎÔÚjavascript·ÃÎÊC#±äÁ¿
·½·¨Ò»£ºÊ¹ÓÃ<%=%>
<input id="Button3" type="button" value="jsµ÷ÓÃc#±äÁ¿" onclick="return Button3_onclick()" />
function Button3_onclick()
{
alert('ÎÒµÄÃû×Ö£º'+ '<%=name %>');
}
cs´úÂëÖеĶ¨Ò壺protected string name = "chenlaing";
·½·¨¶þ£ºÊ¹ÓÃHiddenÒþ²Ø¿Ø¼þ
<input id="Hidden1" runat="server" type="hidden" />
ÔÚcs´úÂëÖиø¸ÃÒþ²Ø¿Ø¼þ¸³Öµ£º Hidden1.Value = "³ÂÁÁ";
function Button3_onclick()
{
alert(document.getElementById("Hidden1").value);
}
·½·¨Èý£ºÔÚcs´úÂëÖÐ×¢²ájs½Å±¾
string tmp = "³ÂÈ«ÓÃ";
ClientScript.RegisterClientScriptBlock(this.GetType(), null, "<script language='javascript'>...var temp='" + tmp + "'</script>");
function Button3_onclick()
{
alert(temp);
}
2. ÔÚjavascript·ÃÎÊC#º¯Êý:
·½·¨Ò»£ºÊ¹ÓÃ<% %>
<script type="text/javascript">...
var s = "<%=ShowBehindInfo("chenliang")%>";
document.write(s);
</script>
csºǫ́´úÂ룺
protected string ShowBehindInfo(string name)
{
return "ÐÕÃû£º" + name;
}
·½·¨¶þ£ºÊ¹ÓÃ<% %>
<script type="text/javascript">...
document.write("<%ShowResult();%>");
</script>
csºǫ́´úÂ룺
protected void ShowResult()
{
Response.Write("ÎÒÊdzÂÈ«ÓÂÆø");
}
·½·¨Èý£º
<style>...
.btn
{...}{
display:none;
}
</style>
<
Ïà¹ØÎĵµ£º
·¢ËͶËÒÔ163ΪÀý
Ò»¡¢asp.net°æ using System.Web.Mail; //ÃüÃû¿Õ¼äÒýÓÃ
c#
MailMessage mail = new MailMessage();
mail.To = "shadow103@qq.com"; //½ÓÊÜÈ˵ÄÓÊÏä
& ......
ÒòΪ¸Õ¸Õ½Ó´¥C#ÓïÑÔ²»¾Ã,ÓÚÊÇÎÒ°Ñ¿ØÖÆ̨¸øÈÓÁË,ÒòΪÎÒÌÖÑá¿ØÖÆ̨!
¶øÊÂʵÉÏÎÒÖ»¶ÔWinForm¼¼Êõ¸ÐÐËȤ,µ«ÊÂʵÉϵ½ÏÖÔÚÎÒ·¢ÏÖASP.Net C#µÄWeb¼¼ÊõÊÇÈÕÏÔÖØÒªÆðÀ´!
ÓÚÊÇ¿ªÊ¼½Ó´¥,¸Õ¸ÕÆð²½ÓÚËùÖª,ÓÈÆäÊÇһЩ×î¼òµ¥µÄ¶«Î÷,µ½ÍøÉÏËÑË÷Á˺ܾÃ,²»ÊÇÌ«ÂÒ¾ÍÊÇ˵²»Çå³þ!
¾Ù¸öÀý×ÓÀ´Ëµ,¾Í˵SessionºÃÁË,²»ÖªµÀÍøÉϵÄÄÇЩ¼Ò»ïµ½µ×ÔÚ½²Ê ......
½ñÌìÔÚÓÃDataListµÄÄ£°åÁеÄʱºòÏ°¹ßÐÔµØÏñÔÚ03ÖÐÄÇÑùÈ¥¸øÄ£°åÁеİó¶¨×ֶμӸö´¦Àíº¯Êý£º
< asp:Label ID = " Label1 " runat = " server " Text = ' <%#ConvertState(Bind("Status"))%> ' ></ asp:Label >
¿ÉÊǾ¹È»³ö´í£ºµ±Ç°ÉÏÏÂÎÄÖв»´æÔÚÃû³Æ“Bind” ......
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml ......
ÎÊ:
Hi,
I have this C#/ASP.NET/.aspx page with a string variable named myString with the value "Mario Gamito".
How can I access "Mario Gamito" from within a JavaScript function, i. e., the variable's value ?
Already tried '" + mystring + "' but it doesn't works.
Any help would be appreciated.
......