0

Home という ASP ページに「SEND」というハイパーリンクがあります。これは次のとおりです。

<asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server" 
                            NavigateUrl='<%# Eval("Post_ID", "~/RCA.aspx?Post_ID={0}") %>' 
                            Text="SEND"></asp:HyperLink>
                    </ItemTemplate>

ユーザーがハイパーリンクをクリックすると、RCA と呼ばれる別のページに移動します。このページにはボタンがあり、ここにコードがあります。

<asp:Button ID="btnRCA" runat="server" onclick="Button1_Click" 
                  Text="Assign RCA" Width="147px" />

このボタンは、HOME ページのハイパーリンクをクリックしたときにのみ表示されるようにします。クリックすると非表示になる別のボタンまたはコントロールを RCA ページに配置する予定です。または、誰かがページを離れる前に、別のコントロールをクリックしてボタンを非表示にする必要があります。誰かがこれで私を助けることができますか? ありがとう

4

2 に答える 2

1

の 2 ページ目で、page_loadこれを試してください。

 protected void Page_Load(object sender, EventArgs e)
  {
        if (Request.QueryString["Post_ID"] != null)
          {
             btnRca.Visible = true;    
          }
   }

他の場合にこのボタンの可視性をどのように処理したいかはわかりませんが、これはあなたの特定の質問に答えるはずです.

于 2012-10-02T23:47:01.670 に答える
1

QueryString パラメータを使用します。

ホーム.aspx

//When linked to RCA.aspx from Home.aspx, a parameter called ShowButton=1 is included 
//in the URL.

<asp:HyperLink ID="HyperLink1" runat="server" 
    NavigateUrl='<%# Eval("Post_ID", "~/RCA.aspx?Post_ID={0}&ShowButton=1") %>' 
    Text="SEND"></asp:HyperLink>

RCA.aspx

//By default, since you want the button to NOT appear for all incoming traffic EXCEPT 
//that which came from Home.aspx, the button's Visible property is set to false.

<asp:Button ID="btnRCA" runat="server" onclick="Button1_Click" 
    Text="Assign RCA" Width="147px" Visible="false" />

RCA.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    //If the querystring has a parameter called ShowButton and it's equal to "1",
    //then set the button to Visible = true.
    //Else, do nothing, keeping the button in it's default, Visible=false state.

    //By putting this in an "IsPostback == false" check, you can guarantee that this will
    //only  happen on first page_load, and won't be triggered again even if you do other 
    //actions in the page that cause Postback

    //For example, if you don't use this !IsPostback check, and you end up creating some 
    //new function that causes the button to be hidden again, but then you make a 
    //selection from a dropdown list that causes postback, you will trigger the call to 
    //make the button Visible again, even though that's probably what you don't want at 
    //this point, since your other new function set it to Visible = false.

    if (!IsPostback)
    {
        if (Request.QueryString["ShowButton"] == "1")
        {
            RCAbtn.Visible = true;
        }

        if (Request.QueryString["Post_ID"] != null)
        {
            //do whatever you need to with the post ID  
        }
    }
}

SomeOtherPage.aspx.cs

Response.Redirect("RCA.aspx?Post_ID=1234"); //button will be invisible

そして後で、ホームからのリダイレクトのように、他のページからリダイレクトして、ボタンを表示させたいとしましょう:

Response.Redirect("RCA.aspx?Post_ID=1234&ShowButton=1"); //button will be visible

URL がごちゃごちゃしているのが気に入らない場合や、自分が行っていることをユーザーの目にはっきりと表示するのが不快に見える場合は、必ずしも "ShowButton" を使用する必要はありません。?Post_ID=1234&fkai3jfkjhsadf=1 と言って、"fkai3jfkjhsadf" のクエリ文字列を確認します。ユーザーの観点からは、私が本当に技術的で暗号化された何かをしているように見えるので、私は時々それをするのが好きで、平易な英語でたくさんの基本的な指示を渡すだけではありません:)独自のクエリ文字列パラメーターを追跡します。


編集:

Post_ID だけで URL を取得したい場合は、次のようにします。

string currenturl = Request.Url.ToString(); //get the current URL
string urlToSend = currenturl.Substring(0, currenturl.IndexOf("?")); //cut off the QueryString entirely
urlToSend += "?Post_ID=" + Request.QueryString["Post_ID"]; //re-append the Post_ID

URL に QueryString がない場合、Substring を呼び出すと例外が発生することに注意してください。そのため、最適な方法 (try/catch など) でパッチを適用してください。

その後、mailMessage.Body で「urlToSend」文字列を使用できるようになります。

于 2012-10-03T02:02:08.180 に答える