asp.net开发随笔

博客主要介绍了ASP.net页面与JavaScript的交互。包括在ASP.net页面执行JSP,在PageLoad中添加属性调用JS函数;在ASP/asp.net页面加载时执行JS过程;以及asp.net页面中服务器控件对JS过程的执行,还给出了相关代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.在ASP.net页面上,执行JSP(1),在PageLoad中,添加.Attributes.Add

    this.imgSelectBatchID.Attributes.Add("onclick","SelectSwatchCheckBill(ctlProductID,ctlNofityCom,ctlCheckBillID,ctlSelBatchID);");

对应的 jsp过程

function SelectSwatchCheckBill(ProductID,CompanyID,InCheckBillID,BatchID)
{
 para=ProductID.value
 para1=CompanyID.value
 var obj = new Object();
 obj.Var1=BatchID;
 obj.Var2=InCheckBillID; 
 window.showModalDialog('../selectforms/SelectFrame.aspx?url='../selectforms/sglSelectSwatch.aspx&type='+para+'&companyid='+para1,obj,
 'dialogheight=580px;dialogwidth=700px;status=no;edge=raised;scroll=no'); 
}

aspx的代码页,取得查询参数

  private string Type
  {
   get
   {
    if (ViewState["Type"] != null)
     return ViewState["Type"].ToString();
    else
     return "";
   }
   set
   {
    ViewState["Type"] = value;
   }
  }

  private string CompanyID
  {
   get
   {
    if (ViewState["CompanyID"] != null)
     return ViewState["CompanyID"].ToString();
    else
     return "";
   }
   set
   {
    ViewState["CompanyID"] = value;
   }
  }

  private void Page_Load(object sender, System.EventArgs e)
  {
   if (!IsPostBack)
   {
    try
    {
     Type = Request.QueryString["type"].ToString();
     CompanyID = Request.QueryString["companyid"].ToString();
    }
    catch
    {}
   }
  }

2.在ASP/asp.net页面加载时,执行JS过程

<script language="javascript">
function PopulateData()
{
}   
</script><script language="javascript" type="text/javascript"> function RemoveItem(ControlName) { &amp;lt;!--EndFragment--&amp;gt; &amp;lt;/BODY&amp;gt;&amp;lt;/HTML&amp;gt; </script><script language="javascript" type="text/javascript"> function RemoveItem(ControlName) { &amp;lt;!--EndFragment--&amp;gt; &amp;lt;/BODY&amp;gt;&amp;lt;/HTML&amp;gt; </script><script language="javascript" type="text/javascript"> function RemoveItem(ControlName) { &amp;lt;!--EndFragment--&amp;gt; &amp;lt;/BODY&amp;gt;&amp;lt;/HTML&amp;gt; </script><body οnlοad="PopulateData()" MS_POSITIONING="GridLayout" background="../../../Images/mailuserbg.gif">

<script language="javascript">
function SetCookie(sName, sValue)
{
 document.cookie = sName + "=" + escape(sValue) + "; ";
}
</script>
<body οnlοad='setInterval("re()",(GetCookie("UDS_RefreshTime"))==null?30000:GetCookie("UDS_RefreshTime"))'>

<BODY οnlοad='javascript: if(this.document.all.txtUsername.value=="") this.document.all.txtUsername.focus();else this.document.all.txtPassword.focus();'>


<body οnlοad="javascript:document.all.MsgSend.txtContent.focus()">

<body οnlοad="document.getElementById('cbx_DeskTop').disabled=true">

<body οnlοad="window.open('StaffData.aspx?'+'<%=Request.ServerVariables["QUERY_STRING"].ToString() %>', '', 'toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');close();">

3.asp.net页面中,服务器控件对JS过程的执行(2)

  <script language="javascript">
   function selQueryBatchEx(para,para1,para1,para2,para3,para4,para5)
   {
    var rtnVal = window.showModalDialog('../../selectform/SelectQueryBatch.aspx?opener=' + para+'&B='+para1+'&C='+para2+'&D='+para3+'&E='+para4+'&F='+para5,'','dialogwidth=600px;dialogheight=400px;status=no;edge=raised;scroll=no');
    if(rtnVal != null)
    {
     if(rtnVal.val2 == 'OK')
     {
      para.value = rtnVal.val1;
      document.forms[0].elements['txtBatch'].value=rtnVal.val1;
      
     }
    }
   }
   

//以下过程和,在PageLoad中,用ImgSelBatch.Attributes.Add 等效

//    this.ImgSelBatch.Attributes.Add("onclick","selQueryBatchEx('txtBatch','txtA','txtA','txtA','txtA','txtA');");
    function SelectBatch(e)
    {
    if(event.srcElement.id=="ImgSelBatch")
    {
     return selQueryBatchEx('txtBatch','txtA','txtA','txtA','txtA','txtA');
    }
    }
    document.onclick = SelectBatch;
    
  </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值