如何从asp webmethod更改iframe的src [英] how to change the src of iframe from asp webmethod

查看:68
本文介绍了如何从asp webmethod更改iframe的src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何从asp webmethod更改iframe的src,如果不可能,我怎么能从webmethod调用javascript函数?

这是我的页面:

 <%@     Page    语言  =  C#    AutoEventWireup   =  true    CodeFile   =  Default.aspx.cs   继承  =  _默认   %>  

< !DOCTYPE html >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > ; 更改iframe src < / title >
< script src = jquery-1.9。 1.js > < / script >
< / head >
< body >
< 表格 id = form1 runat = server >
< div > ;
< 输入 type = button name = 名称 value = 点击更改iframe的src onclick = change_url( '1'); / > ;
< / div >
< div >
< iframe id = myFrame width = < span class =code-keyword> 100% height = 100% > < / iframe >
< / div >
< / form >
< script 类型 = text / ecmascript >
function change_url(输入){
$ .ajax( {
类型: POST,
url: ./ Default.aspx / GetData
data:' {id:' + input + ' }'
contentType: 应用/ JSON; charset = utf-8
dataType: json
成功: function (msg){
alert(' iframe src已成功更改!');
}
});
}
< ; / script >
< / body >
< / html > ;





这是我的代码:



 <%@    < span class =code-leadattribute> Page    语言  =  C#    AutoEventWireup   =  true    CodeFile   =  Default.aspx.cs   继承  =  _默认   %>  

< !DOCTYPE html >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > 更改iframe src < / title >
< script src = jquery-1.9.1.js > < / script >
< / head >
< body >
< 表格 id = form1 runat = server >
< ; div >
< 输入 type = 按钮 名称 = 名称 value = 点击更改iframe的src onclick = change_url('1'); / >
< < span class =code-leadattribute> / div
>
< div >
< iframe id = myFrame 宽度 = 100% height = 100% > < / iframe >
< / div >
< < span class =code-leadattribute> / form >
< script type = text / ecmascript >
< span class =code-keyword> function change_url(input){
$ .ajax({
type: < span class =code-string> POST,
url: ./ Default .aspx / GetData
data:' {id:'' + input + ' }',
contentType: application / json; charset = utf-8
dataType: json
成功: function (msg){
alert(' iframe src已成功更改!');
}
});
}
< ; / script >
< / body >
< / html > ;

解决方案

.ajax({
type: POST
url: ./ Default.aspx / GetData
data:' {id:' + input + ' }'
contentType: application / JSON; charset = utf-8
dataType: json
成功: function (msg){
alert(' iframe src已成功更改!');
}
});
}
< ; / script >
< / body >
< / html > ;





这是我的代码:



 <%@    < span class =code-leadattribute> Page    语言  =  C#    AutoEventWireup   =  true    CodeFile   =  Default.aspx.cs   继承  =  _默认   %>  

< !DOCTYPE html >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > 更改iframe src < / title >
< script src = jquery-1.9.1.js > < / script >
< / head >
< body >
< 表格 id = form1 runat = server >
< ; div >
< 输入 type = 按钮 名称 = 名称 value = 点击更改iframe的src onclick = change_url('1'); / >
< < span class =code-leadattribute> / div
>
< div >
< iframe id = myFrame 宽度 = 100% height = 100% > < / iframe >
< / div >
< < span class =code-leadattribute> / form >
< script type = text / ecmascript >
< span class =code-keyword> function change_url(input){


.ajax({
type: POST
url: ./ Default.aspx / GetData
data:' {id :' + input + ' }'
contentType: application / json; charset = utf-8
dataType: json
成功: function (msg){
alert(' iframe src已成功更改!');
}
});
}
< ; / script >
< / body >
< / html > ;


由于您已经有jquery代码来调用webservice,只需更改.ajax成功函数中的iframe.src。

Hello all,

how can i change the src of iframe from asp webmethod, if it is impossible, how can i call javascript function from webmethod??
this is my page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change iframe src</title>
    <script src="jquery-1.9.1.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="button" name="name" value="Click to change the src of iframe" onclick="change_url('1');" />
        </div>
        <div>
            <iframe id="myFrame" width="100%" height="100%"></iframe>
        </div>
    </form>
    <script type="text/ecmascript">
        function change_url(input) {
            $.ajax({
                type: "POST",
                url: "./Default.aspx/GetData",
                data: '{"id":"' + input + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    alert('iframe src was changed successfully!');
                }
            });
        }
    </script>
</body>
</html>



and this is my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change iframe src</title>
    <script src="jquery-1.9.1.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="button" name="name" value="Click to change the src of iframe" onclick="change_url('1');" />
        </div>
        <div>
            <iframe id="myFrame" width="100%" height="100%"></iframe>
        </div>
    </form>
    <script type="text/ecmascript">
        function change_url(input) {
            $.ajax({
                type: "POST",
                url: "./Default.aspx/GetData",
                data: '{"id":"' + input + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    alert('iframe src was changed successfully!');
                }
            });
        }
    </script>
</body>
</html>

解决方案

.ajax({ type: "POST", url: "./Default.aspx/GetData", data: '{"id":"' + input + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert('iframe src was changed successfully!'); } }); } </script> </body> </html>



and this is my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change iframe src</title>
    <script src="jquery-1.9.1.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="button" name="name" value="Click to change the src of iframe" onclick="change_url('1');" />
        </div>
        <div>
            <iframe id="myFrame" width="100%" height="100%"></iframe>
        </div>
    </form>
    <script type="text/ecmascript">
        function change_url(input) {


.ajax({ type: "POST", url: "./Default.aspx/GetData", data: '{"id":"' + input + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert('iframe src was changed successfully!'); } }); } </script> </body> </html>


Since you already have jquery code to call the webservice, just change the iframe.src in your success function of .ajax.


这篇关于如何从asp webmethod更改iframe的src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆