2012-02-21 19 views
0

をリダイレクトするためのページ、.NETは、Visual Studio 2010のフィラーC#を使用して外部URL

私はGridViewの上のハイパーリンクをユーザーがクリックするnavigationurlは、手順 1つの呼び出しWebサービスを使ってその場で作成されなければならない状況があるといくつかの値を渡して、コントロールのナビゲーションURLにアタッチする必要がある新しいidkeyを受け取ると、これはRowDataBoundイベントの下で実行されますが、グリッド内の各行に対してwebserviceに無駄な呼び出しを行います。代わりに、ユーザーがリンクをクリックしたときにこれを実行したいのですか?

私が考えている別のアイディアは、ページをリダイレクトする間にページを使うことですが、それは自動提出する必要がありますか?これに任意の手がかり???またはより良いやり方?

おかげ

 <asp:GridView ID="GridViewLinkedService" runat="server" AutoGenerateColumns="False" DataKeyNames = "applicationId" 
       DataSourceID="ObjectDataLinkedService" Height="213px" Width="897px"> 
       <Columns> 
        <asp:BoundField DataField="applicationId" HeaderText="Application ID" Visible ="true" 
         SortExpression="applicationId"> 
         <HeaderStyle BackColor="#4B6C9E" BorderStyle="Solid" Font-Bold="True" 
         Font-Names="Verdana" Font-Size="Small" ForeColor="White" /> 
        <ItemStyle Width="10px" /> 
         </asp:BoundField> 
        <asp:BoundField DataField="referenceNumber" HeaderText="Reference Number" 
         SortExpression="referenceNumber" > 
        <HeaderStyle BackColor="#4B6C9E" BorderStyle="Solid" Font-Bold="True" 
         Font-Names="Verdana" Font-Size="Small" ForeColor="White" /> 
        <ItemStyle Width="30px" /> 
        </asp:BoundField> 
        <asp:BoundField DataField="applicationName" HeaderText="Application Name" 
         SortExpression="applicationName" > 
          <HeaderStyle BackColor="#4B6C9E" BorderStyle="Solid" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="White"/> 
         </asp:BoundField>      
        <asp:BoundField DataField="address" HeaderText="Address" 
         SortExpression="address" > 
          <HeaderStyle BackColor="#4B6C9E" BorderStyle="Solid" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="White" /> 
         </asp:BoundField> 

       </Columns> 

Hyperlink column is added in the Pageload 

    HyperLinkField LinksBoundField = new HyperLinkField(); 
      string[] dataNavigateUrlFields = {"link"}; 
      LinksBoundField.DataTextField = "link"; 
      LinksBoundField.DataNavigateUrlFields = dataNavigateUrlFields; 
**LinksBoundField.NavigateUrl; //call webservice(send appid and refno) and append newtoken to url (reieved from datasource link)** 
      LinksBoundField.DataNavigateUrlFormatString = "http://" + Helper.IP + "/" + Helper.SiteName + "/" + Helper.ThirdPartyAccess + "?value={0}&token=" + Session["Token"]; 
      LinksBoundField.HeaderText = "Link"; 
      LinksBoundField.Target = "_blank";   
        GridViewLinkedService.Columns.Add(LinksBoundField);  
       GridViewLinkedService.RowDataBound += new GridViewRowEventHandler(grdView_RowDataBound); 
+0

ここからASHXファイルの代わりに、ASPXを使用してのヒントを得た、非常によく

おかげで動作します10? – Polity

+0

@Polityはおそらくビジュアルスタジオ2010を意味します – Aristos

+0

@Polity yes VS 2010 – Gauls

答えて

0

はdatanavigationコード

を削除しましたgrdviewLink.NavigateUrlで渡されたURL以下に変更
string[] dataNavigateUrlFields = {"link"};    LinksBoundField.DataTextField = "link";    LinksBoundField.DataNavigateUrlFields = dataNavigateUrlFields; 

はアップごちゃ混ぜにされません。

<asp:HyperLinkField DataTextField="link" HeaderText="Multi-Link" Target="_blank" ItemStyle-Width = "5px" ItemStyle-Wrap ="true"> 
        <HeaderStyle Wrap="True" Width="5px" BackColor="#4B6C9E" BorderStyle="Solid" Font-Bold="True" Font-Names="Verdana" ForeColor="White"/> 

        </asp:HyperLinkField>  

protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e) 
     { 
      string strvalue = "";   
      string strRef = ""; 
      string strAppId = ""; 
      foreach (GridViewRow row in GridViewLinkedService.Rows) 
      { 
       if (row.RowType == DataControlRowType.DataRow) 
       { //reference and appid 
        strAppId = row.Cells[0].Text; 
        strRef = row.Cells[1].Text; 
        HyperLink grdviewLink = (HyperLink)row.Cells[6].Controls[0]; 
        strvalue = grdviewLink.Text; 
        grdviewLink.NavigateUrl = "~/My Service/Navigate.ashx?AppID=" + strAppId.ToString() + "&Ref=" + strRef.ToString() + "&nurl=" + Server.UrlEncode(strvalue); 

       } 
      } 
     } 

Navigate.ashx

public void ProcessRequest(HttpContext context) 
     { 
      if (context.Request.QueryString.GetValues("AppID") != null) 
      { 
       appid = context.Request.QueryString.GetValues("AppID")[0].ToString(); 
      } 

      if (context.Request.QueryString.GetValues("Ref") != null) 
      { 
       refno = context.Request.QueryString.GetValues("Ref")[0].ToString(); 
      } 

      if (context.Request.QueryString.GetValues("nurl") != null) 
      { 

       nurl = HttpUtility.UrlDecode(context.Request.QueryString.GetValues("nurl")[0].ToString()); 
      } 

ファイルこれはぞんざいにC#.NET何ですか

ashx

2

は確かにあなたが取ることができる一つのアプローチは、フィラーページに必要ではない、jQueryのを使用して、クライアント側でのリンクを生成することです...例えば

、次の表いくつかのダミーアンカータグを持っている...

<table cellspacing="0" border="1" id="grdSpys"> 
<tbody> 
    <tr> 
     <th align="center" scope="col">Name<th align="center" scope="col">Action</th> 
    </tr> 
    <tr> 
     <td>Mr A</td> 
     <td> 
      <a href="#">Click Me</a> 
      <input type="hidden" value="Anthony" /> 
     </td> 
    </tr> 
    <tr> 
     <td>Mr B</td> 
     <td> 
      <a href="#">Click Me</a> 
      <input type="hidden" value="Barry" /> 
     </td> 
    </tr> 
    <tr> 
     <td>Mr C</td> 
     <td> 
      <a href="#">Click Me</a> 
      <input type="hidden" value="Carl" /> 
     </td> 
    </tr> 
    <tr> 
     <td>Mr D</td> 
     <td> 
      <a href="#">Click Me</a> 
      <input type="hidden" value="Don" /> 
     </td> 
    </tr> 
    <tr> 
     <td>Mr E</td> 
     <td> 
      <a href="#">Click Me</a> 
      <input type="hidden" value="Ethan" /> 
     </td> 
    </tr> 
</tbody> 

とUSIによって、 Jqueryを使用すると、すべてのリンクをバインドして1つの特定のアクション、つまりWebサービスに移動することができます。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script> 

    <script type="text/javascript"> 

     $(document).ready(function() { 
      $("#grdSpys a").bind('click' , function() { 
       var secretName = $(this).next().val(); 
       alert('goto the webservice, tell them it is ' + secretName); 
      }); 
     }); 

    </script> 

トリックは(上記の例では、我々は隠された入力とDOMナビゲーションを使用して...あなたのリンクを取得するために、適切なJquery selectorsを利用することであるし、必要に応じて任意のパラメータを通過

+0

htmlの「クリック」はどこですか?私はそれを使用していないjqueryで非常に複雑に聞こえます。 – Gauls

+0

'click'はJavascriptのマウスイベントです。各グリッドビューの行またはループをリンクする必要はありません(JQueryセレクターがそれを行います)。リダイレクトがクライアントで発生する可能性があるため、URLを追加する必要はありませんあなたがJavascriptやJqueryに似ていないのであれば、サーバー側のコードに対してクライアント側のコードを実行する機能と利点をチェックしたいかもしれませんが、 – SeanCocteau

+0

@ SeanCocteau:説明してくれてありがとう。 – Gauls

関連する問題