asp.net开发中经常用到的方法

时间:2022-08-08 22:15:44
---天气插件---
<iframe width="560" scrolling="no" height="23" frameborder="0" allowtransparency="true" src="http://i.tianqi.com/index.php?c=code&id=1&icon=1&wind=1&num=2"></iframe>
---后台调用js---

ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert1();</script>");

---客户端弹出确认框---
OnClientClick="return confirm('您确认删除该记录吗?');"

---日历插件---

my97datepicker

---webconfig连接字符串---

<connectionStrings>
    <add name="constring" connectionString="server=.;Integrated security = true;database=OfficeManage" />

</connectionStrings>
<add key="ConnectionString" value="server=.;database=Board;uid=B;pwd=sa"/>

---dropdownlist进行操作---
DataSet ds = Operation.GetDataSet("SELECT DepartmentId,DepartmentName FROM dbo.tabP_Department");
ddlDepartment.DataValueField = "DepartmentId";
ddlDepartment.DataTextField = "DepartmentName";
ddlDepartment.DataSource = ds;
ddlDepartment.DataBind();

ddlDepartment.Items.Insert(0,new ListItem("请选择发布部门","0"));

---服务器伪静态添加--- 
脚本映射,要把.html文件映射到asp.net处理程序上

---设置textbox不可写只能选---
加入onfocus="this.blur()"

 
---框架布局---

<frameset rows="*,30" cols="*" frameborder="no" border="0" framespacing="0">
<frameset cols="180,*" frameborder="no" border="0" framespacing="0">
<frame src="Default.aspx" name=list marginWidth=0 marginHeight=0 id="leftFrame" frameBorder=0 noResize scrolling=yes longDesc=""/>
<frame src="register.html" name="mainFrame" id="mainFrame" />
</frameset>
<frame src="Default1.aspx" name="bottomFrame" scrolling="yes" noresize="noresize" id="bottomFrame" />
</frameset>
<noframes>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body></noframes>

---js关键判断---

<script Language="JavaScript">
function delete_product(product_id)
{
msg='确认要删除该物品,及相关的物品登记信息么?';
if(window.confirm(msg))
{
URL="delete.aspx?product_id=" + product_id +"&page=<%=ViewState["CurrentPage"]%>";
window.location=URL;
}
}
<a href="javascript:delete_product(<%#DataBinder.Eval(Container.DataItem,"ProductId")%>);">删除</a>

if (document.getElementById("registerdate").value == "") {
alert("登记日期不能为空!");
document.getElementById("registerdate").focus();
return (false);
}

</script>

----验证码关键前台代码---

<head runat="server">
<title></title>
<script type="text/javascript">
function ChangeCode() {

var date = new Date();
var myImg = document.getElementById("ImageCheck");
var GUID = document.getElementById("lblGUID");

myImg.src = "../ValidateCode.aspx?GUID=" + GUID.innerHTML + "&flag=" + date.getMilliseconds()

return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
验证码:
<input class="nemo01" id="CheckCode" tabindex="3" maxlength="22" size="11" name="user"
runat="server">
<a id="A2" href="" onclick="ChangeCode();return false;">
<asp:Image ID="ImageCheck" runat="server" ImageUrl="../ValidateCode.aspx?GUID=GUID"
ImageAlign="AbsMiddle" ToolTip="看不清,换一个"></asp:Image></a>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>