×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

好了,看这里:

.aspx

<table width="500">
<tr>
<td>
<iframe height="300" width="400" id="f1" src="" runat="server"></iframe>
</td>
</tr>
</table>

.cs
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlContainerControl f1;


private void Button1_Click(object sender, System.EventArgs e)
{
f1.Attributes["src"]="http://www.microsoft.com";
}

private void Button2_Click(object sender, System.EventArgs e)
{
f1.Attributes["src"]="http://www.google.com";
}
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / ASP.net高手请进
    我想在网页里放一个固定的窗口,这个窗口不做别的,只用来显示其它的网页用,比如放新浪或者网易.但在窗口里放的网页需要是动态的,我需要按一个键窗口里显示新浪,按另外一个键窗口里显示网易,也就是说我要用程序来设置此窗口的URL.请教各位高手,在asp.net里是否提供这样的控件来实现此功能?多谢!
    • IFRAME, FRAME
      • 多谢!不过iframe是client端的,不知asp.net是否提供server端的控件?这样实现起来会方便许多(因为url的生成逻辑比较复杂)
        • 你那几个键作成提交form不就行啦? target都在那个frame里面...
          • 也是,就是麻烦些.本来还想偷偷懒....
        • set iframe's runat="server"
    • Option 1: web user control; Option 2: Reload page with dynamically configured request string each time you want change. (The first option seems to be easier. )
      • 多谢!第一种方案比较好,不过不知道如何做这样的user control. ASP.net的image control都能设置url,为什么.net不提供能实现此功能的control呢?
        用iframe就是用的第二种的方案,我知道能行得通,不过调了一整天都没有调出来,不知道问题出在哪.
        • 做一个空白的.ascx, 在Page_Load里面写Response.Redirect("http://XXXX"), 当然得自己生成URL, 然后把它拖进你的网页...
          • 这个方案看起来比用下面的用ATTRIBUTE 更简单, 有没有DX 有雅兴试验一下行不行. 我现在没有VS, 就免啦.
            • 这个办法把页面分成了两个文件, 从程序的重复使用角度说是可取的, 但是对于目前这个问题, 组件里面只有一行程序, 好象用不着这样...
              • yes, using attribute is much easier. Before I just didn't know I could set those HTML elements' attributes using .NET. Because of this, in fact, we can consider HTML elements as web control too.
    • Donot get mad! you are another guy to enter into ms trap. your case can easily be handled by html, why bother so-call web control. Donot be mad!!! Good day
      • 这个HTML除了FRAME还有其它方法吗? 楼主已经说了不想用FRAME.
        • No
        • I do not particulary hate to use frame or iframe. It is just because they make programming much more difficult. After all, I need to get those dynamic URL generated by server and database,
          • 你这个动态URL是每次load page更新一次,还是经常更新?
            • often
            • almost every button in the webpage has to change the URL dynamically
              • 等一下,我正在做个试验
              • 好了,看这里:
                .aspx

                <table width="500">
                <tr>
                <td>
                <iframe height="300" width="400" id="f1" src="" runat="server"></iframe>
                </td>
                </tr>
                </table>

                .cs
                protected System.Web.UI.WebControls.Button Button2;
                protected System.Web.UI.WebControls.Button Button1;
                protected System.Web.UI.HtmlControls.HtmlContainerControl f1;


                private void Button1_Click(object sender, System.EventArgs e)
                {
                f1.Attributes["src"]="http://www.microsoft.com";
                }

                private void Button2_Click(object sender, System.EventArgs e)
                {
                f1.Attributes["src"]="http://www.google.com";
                }
                • Great!!!!!! Thank you very much .....This is what exactly what I want.
                  I have believed microsoft must have provided something to solve such question
                  • 这里关键的地方就是要把client side的control 在code behind里面定义出来,这样就可以为所欲为了,基本上。:)
                    • many thanks to luoboyang!!! I have implemented your solution in my program. I guess it's the easiest way that I can wish.
                      • My pleasure! 共同学习,共同提高,共同进步。:))
        • but iframe or frame are only good when you already get the URL in client site. BTW, I do not think it is a trap of Microsoft. If you wanna such have website with such a function
          , it won't be easy for any other programming tools either.
          • using javascript plus xmlhttp component plus layer will give you all flexibility
            • Can you provide an example with what you have mentioned? Thanks.
              • some hint
                function getpage()
                {

                var objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
                objHTTP.Open('GET',http://www.yahoo.com',false)
                objHTTP.Send()
                var txt= objHTTP.ResponseText
                ...
                }
                This will get content from site,then write the txt into layer you created, if you make url to be variable, you will get page dynamically when you click button

                ..
                • Not that easy pal, and for some dynamic content it will failed.
    • 有那么麻烦么?
      <html>
      <head>
      <script language="JavaScript">
      <!--

      var i = 0;
      var j = 0;
      var urls1 = new Array();
      urls1[0] = "http://www.cnn.com";
      urls1[1] = "http://www.yahoo.com";
      var urls2 = new Array();
      urls2[0] = "http://www.slashdot.org";
      urls2[1] = "http://www.sina.com.cn";

      function doSwitch(use_list) {

      var o = document.getElementById("dyn");

      if(o != null) {
      if(use_list == 1)
      o.src = urls1[i++%2];
      else
      o.src = urls2[j++%2];
      o.refresh();
      }
      }
      //-->
      </script>
      </head>
      <body>
      <input type="button" value="press me 1!" onClick="javascript: return doSwitch(1);">
      <input type="button" value="press me 2!" onClick="javascript: return doSwitch(2);">
      <iframe id="dyn" src="url"></iframe>
      </body>
      </html>
      • the example you gave is not a solution. It is easy because you use JavaScript and define the URLs in the program in the client site already. How do you get those URLs if they are in the database?
        • #2086436
        • You can pass the value from database to javascript function.
        • I don't like some ASP dot Net developer, wonder why? not because they don't understamd ASP can output dynamic content, but their attitude, hehe.
          • well, my attitude is good. I have thanked you, right? :-) BTW, I am not a .net developer. I used to be an Oracle DBA but now I am just a student.
            I like to ask questions. Your solution just doesn't seem to fit my requirement. exactly. Fortunately, finnally I got the solution I need.
      • 你的code不错,就是不是楼主的要求。全在client side了。:)
        • Thanks, your solution fits better.
      • This guy is something. let .cs output html for you, donot use web-control. While, somebody bing-de-bu-qing.
        • well, don't be so critical. every person has his(her) own preference and opinions. You think it is impossible, right? However, luoboyang gave me the best solution I want.....
    • No way.
      It's impossible to create a server side control acting as a browser.
      • 没有才要写啊.