传值问题

using System;
using System.Web ;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;


namespace DataTransmit
{
 /// <summary>
 /// WebCustomControl1 の概要の説明です。
 /// </summary>
 [DefaultProperty("Text"),
  ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
 public class DataPostClass : System.Web.UI.WebControls.WebControl
 {
  private string text;
 

  [Bindable(true),
   Category("Appearance"),
   DefaultValue("")]
  public string Text
  {
   get
   {
    return text;
   }
   set
   {
    text=value;
   }

  }

  /// <summary>
  /// このコントロールを指定された出力パラメータに描画します。
  /// </summary>
  /// <param name="output"> 書き込む HTML ライタ </param>
  protected override void Render(HtmlTextWriter output)
  {
   output.Write(text);
  }

  //方法1:session cookieで、 一つか二つのサイトの間に、戻るのは出来る
  public string FormPostCookie(string UrlDestination,string PostValues,int PostNum)
  {
   string [,]NameValues;
   string FormStr;
   NameValues=new string[PostNum,2];
   
   StrDiv (PostNum,PostValues,NameValues);
   
  // FormStr="var href=window.location.href;var cookieEnabled=(navigator.cookieEnabled)? true : false;if (typeof navigator.cookieEnabled=='undefined'&&!cookieEnabled){document.cookie='testcookie';cookieEnabled=(document.cookie.indexOf('testcookie')!=-1)? true : false;}if(cookieEnabled)";
   FormStr="<script language='javascript'>var href=window.location.href;function post(){document.write('<form name=myForm></form>');var a=document.cookie;var index1=a.indexOf('num=1');var index2=a.indexOf('num=2');var index3=href.indexOf('#');if(((index1==-1)&&(index2==-1))||(index3==-1)){";
   for(int i=0;i<PostNum;i++)
   {
    FormStr+="myForm.innerHTML+='<textarea name="+NameValues[i,0]+">"+NameValues[i,1]+"</textarea>';";
   }
   FormStr+="myForm.action='"+UrlDestination+"';myForm.method='POST';document.cookie='num=1';window.location.href=href+'#';myForm.submit();}";
   FormStr+="else{if(index1!=-1){document.cookie='num=2';history.back();}";
   FormStr+="else{document.cookie='num=1';history.forward();}}}";
   FormStr+="var cookieEnabled=(navigator.cookieEnabled)? true : false;if (typeof navigator.cookieEnabled=='undefined'&&!cookieEnabled){document.cookie='testcookie';cookieEnabled=(document.cookie.indexOf('testcookie')!=-1)? true : false;}if(cookieEnabled)post();else{if(confirm('cookieが利用するのは必要で,セットしてください!//n//nボタンOKをクリックして,Cookieセット説明ページに入る')) window.location.href='CookieSet.htm';else window.location.href=href;}</script>";
   return FormStr;

  }

  

  //方法2:JavaScriptとアドレス欄で、一つか二つのサイトの間に、戻るのは出来る
  public string FormPostUrl(string UrlDestination,string PostValues,int PostNum)
  {
   string [,]NameValues;
   string FormStr;
   NameValues=new string[PostNum,2];
   
   StrDiv (PostNum,PostValues,NameValues);
   
    FormStr="<script language='javascript'>document.write('<form name=myForm></form>');var a=window.location.href;var index1=a.indexOf('#');var index2=a.indexOf('##');if(index1==-1){";
    for(int i=0;i<PostNum;i++)
    {
     FormStr+="myForm.innerHTML+='<textarea name="+NameValues[i,0]+">"+NameValues[i,1]+"</textarea>';";
    }
    FormStr+="myForm.action='"+UrlDestination+"';myForm.method='POST';window.location.href=a+'#';myForm.submit();}";
    FormStr+="else{if(index2!=-1){window.location.href=a.substring(0,index2)+'#';history.forward();}";

//    戻った後、UrlSourseというページがブラウザーから取って、それに、進むボタンが利用できる。
    FormStr+="else{window.location.href=a.substring(0,index1)+'##';history.back();}}</script>";
    
   return FormStr;

//    戻った後、UrlSourseというページがリロードして、それに、進むボタンが利用できる
//    HttpContext.Current .Response.Write ("else{window.location.href=b.substring(0,a.length)+'##';history.back();window.location.href=a;}}</script>");
   
    
//    戻った後、UrlSourseというページがリロードして、それに、進むボタンが利用できなくになる
//    HttpContext.Current .Response.Write ("else{window.location.href=a;}}</script>");
   
  } 


  public string FormPostWin(string UrlDestination,string PostValues,int PostNum,string WinStr)
  {
   string [,]NameValues;
   string FormStr;
   NameValues=new string[PostNum,2];
   
   StrDiv (PostNum,PostValues,NameValues);

    FormStr="<script language='javascript'>var a=window.location.href;";
    FormStr+="document.write('<form name=myForm target=newwin></form>');";
    for(int i=0;i<PostNum;i++)
    {
     //HttpContext.Current .Response.Write ("myForm.innerHTML+='<input type=hidden name="+NameValues[i,0]+" value="+NameValues[i,1]+">';");
     FormStr+="myForm.innerHTML+='<textarea name="+NameValues[i,0]+">"+NameValues[i,1]+"</textarea>';";
    }
    FormStr+="myForm.action='"+UrlDestination+"';myForm.method='POST';window.open ('about:blank','newwin','"+WinStr+"');myForm.submit();window.location.href=a;</script>";
   
   return FormStr;

   
  }

 

//  PostValuesを処理して、名によって、分割する。
  public void StrDiv(int n,string PostStr,string [,]PostValues)
  {
   string TempPostStr=PostStr.Replace ("/r/n","");

   string []SubPostStr;
   SubPostStr=new string [n];

   try
   {
    if(n>1)
    {
     SubPostStr=TempPostStr.Split('&');
    }
    if(n==1)
    {
     SubPostStr[0]=TempPostStr;
    }

    for(int i=0;i<n;i++)
    {
     string Temp=SubPostStr[i];
     int len=Temp.Length;
     int TempLen=Temp.IndexOf ("=");
     if(TempLen!=-1)
     {
      PostValues[i,0]=Temp.Substring (0,TempLen);
      PostValues[i,1]=Temp.Substring (TempLen+1,len-TempLen-1);
     }

    }

   }

   catch
   {
    
   }
  }


 }
}

引用时:

string Parame="id="+txtVenderCD.Text+"&pwd="+txtVenderPwd.Text+"&type="+type+"&prepage="+prepage;
   string Javastr3;
   DataTransmit.DataPostClass  IndexConn=new DataTransmit.DataPostClass();
   Javastr3=IndexConn.FormPostCookie("Gate.aspx",Parame,4);
   IndexConn.Dispose();
   Response.Write(Javastr3);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值