How to get iFrame values from one asp to other asp page

Discussion in 'C#' started by Karthik chennappan, Oct 25, 2010.

  1. #1
    Hi,

    I have an ASP page (Page 1) and in that ASP page i have iFrame control. This iFrame internally calling the .aspx page.

    I Have another ASP page (page 2) and from this ASP page i am calling the Page 1 to get the iFrame control values.

    i am getting the values but my problem is,

    only i am getting the values some minutes later (if page has some javascript error). if the page loaded without error (means loaded fastly) then the value is not coming, because the page 2 javascript is called before Page 1 iFrame aspx page render.
    it requires some timedelay to load page 1 with iFrame page.

    Please suggest what should i do to resolve the above solution?

    Thanks,
    Karthik C.
     
    Karthik chennappan, Oct 25, 2010 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Can you post the code that you have?
     
    camjohnson95, Oct 25, 2010 IP
  3. Karthik chennappan

    Karthik chennappan Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    -----calling aspx page from asp----
    <html>
    <body onunload="">
    <form id="frmIndicesFrame">
    <iframe id="frameIndices" runat="server" width="100%" height="0%" frameborder="no" src="../performancedotnet/IndicesList.aspx">
    </iframe>
    </form>
    </body>
    </html>

    ------retrive values from iframe control-------
    <html>
    <body onload="Page_Load()">
    <form id="CallIndices">

    </form>
    <script language="javascript">
    function Page_Load()
    {

    var Result = window.frames["frameIndices"].document.getElementById('divIndices').innerText;
    //document.forms[0].hdnIndicesList.value = "Hi";
    alert(Result);
    }

    </script>
    </body>
    </html>
    <%
    Dim IndicesList
    IndicesList = Request.Form("hdnIndicesList")
    Response.Write IndicesList

    %>


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

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" id="htmlIndices">
    <head runat="server">
    <title>Untitled Page</title>
    <script language="javascript">
    var xmlHttp;
    var requestURL = 'http://localhost:2149/ClientTestApp/Default.aspx?Param=AjaxCall';
    var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
    var is_ie5 = (navigator.appVersion.indexOf("MSIE 6.0")!=-1) ? 1 : 0;
    var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
    var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

    function show_data(strName){ debugger;
    if (strName.length > 0){
    var url = requestURL + strName;
    xmlHttp = GetXmlHttpObject(stateChangeHandler);
    xmlHttp_Get(xmlHttp, url);
    }
    else {
    document.getElementById('divIndices').innerHTML = '';
    }
    }
    function stateChangeHandler()
    {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
    var str = xmlHttp.responseText;

    var startIndex = str.indexOf(document.getElementsByTagName("span")[0].id);
    var EndIndex = str.indexOf("</" + document.getElementsByTagName("span")[0].tagName.toLowerCase() + ">");
    var Result = str.substr(startIndex, EndIndex);
    Result = Result.substr(Result.indexOf("<Table>"), Result.indexOf("</Table>")-4);
    document.write(Result);
    }
    }

    function xmlHttp_Get(xmlhttp, url) {
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
    }

    function GetXmlHttpObject(handler) {
    var objXmlHttp = null;
    if (is_ie){
    var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
    try{
    objXmlHttp = new ActiveXObject(strObjName);
    objXmlHttp.onreadystatechange = handler;
    }
    catch(e){
    alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
    return;
    }
    }
    else if (is_opera){
    alert('Opera detected. The page may not behave as expected.');
    return;
    }
    else{
    objXmlHttp = new XMLHttpRequest();
    objXmlHttp.onload = handler;
    objXmlHttp.onerror = handler;
    }
    return objXmlHttp;
    }
    </script>
    </head>
    <body onload="show_data('1');">
    <form id="form1" runat="server">
    <asp:Label ID="lblIndices" runat="server"></asp:Label>

    </div>
    </form>
    </body>
    </html>


    ----aspx server side code----
    protected void Page_Load(object sender, EventArgs e)
    {
    try
    {
    if (Request["Param"] == "AjaxCall1")
    {
    OdbcCommand odbcSpCmd;
    OdbcParameter odbcParam;
    OdbcConnection odbcCon;

    //Change the connection string to use your SQL Server.
    odbcCon = new OdbcConnection("DSN=PVMDD001;UID=P44BMJ;PWD=Hema@@88;");

    //Use ODBC call syntax.
    odbcSpCmd = new OdbcCommand("{CALL DBTPVMD.VMDP301(0,0,0,0,0,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", odbcCon);

    odbcParam = odbcSpCmd.Parameters.Add("@LS_IP_PARM1", OdbcType.Char);
    odbcParam.Value = "0";
    odbcParam = odbcSpCmd.Parameters.Add("@LS_IP_PARM2", OdbcType.Char);
    odbcParam.Value = "0";
    odbcParam = odbcSpCmd.Parameters.Add("@LS_IP_PARM3", OdbcType.Char);
    odbcParam.Value = "0";
    odbcParam = odbcSpCmd.Parameters.Add("@LS_IP_PARM4", OdbcType.Char);
    odbcParam.Value = "0";
    odbcParam = odbcSpCmd.Parameters.Add("@KEY_ACCT", OdbcType.Char);
    odbcParam.Value = "0";

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM1", OdbcType.Char, 4);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM2", OdbcType.Char, 4);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM3", OdbcType.Char, 80);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM4", OdbcType.Char, 10);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM5", OdbcType.Char, 1);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM6", OdbcType.Char, 1);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM7", OdbcType.Char, 9);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM8", OdbcType.Char, 9);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM9", OdbcType.Char, 9);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM10", OdbcType.Char, 4);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM11", OdbcType.Char, 40);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM12", OdbcType.Char, 1);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM13", OdbcType.Char, 1);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM14", OdbcType.Char, 1);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM15", OdbcType.Char, 1);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM16", OdbcType.Decimal, 4);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM17", OdbcType.Decimal, 4);
    odbcParam.Direction = ParameterDirection.Output;

    odbcParam = odbcSpCmd.Parameters.Add("@LS_OP_PARM18", OdbcType.Decimal, 4);
    odbcParam.Direction = ParameterDirection.Output;

    odbcCon.Open();

    OdbcDataAdapter odbcadp = new OdbcDataAdapter(odbcSpCmd);
    DataSet odbcds = new DataSet();
    odbcadp.Fill(odbcds);
    //dgIndicesList.DataSource = odbcds;
    //dgIndicesList.DataBind();

    GetDivElements(odbcds);

    odbcCon.Close();
    }
    }
    catch (Exception ex)
    {
    }
    }


    public void GetDivElements(DataSet odbcds)
    {
    // Initialize StringWriter instance.
    StringWriter stringWriter = new StringWriter();
    string sFormHtml = string.Empty;
    // Put HtmlTextWriter in using block because it needs to call Dispose.
    using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
    {
    sFormHtml += "<Table>";
    for (int i = 0; i < odbcds.Tables[0].Rows.Count; i++)
    {
    sFormHtml += "<tr>";
    if (i < 25)
    {
    sFormHtml += "<td>";
    sFormHtml += odbcds.Tables[0].Rows[3].ToString().Trim();
    sFormHtml += "</td>";
    }
    else if (i < 50)
    {
    sFormHtml += "<td>";
    sFormHtml += odbcds.Tables[0].Rows[3].ToString().Trim();
    sFormHtml += "</td>";
    }
    else
    {
    sFormHtml += "<td>";
    sFormHtml += odbcds.Tables[0].Rows[3].ToString().Trim();
    sFormHtml += "</td>";
    }
    sFormHtml += "</tr>";
    }
    sFormHtml += "</Table>";
    writer.Write(sFormHtml);
    }
    lblIndices.Text = stringWriter.ToString();
    }
     
    Karthik chennappan, Oct 26, 2010 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    why are you using an iframe rather then just calling the aspx page itself?

    
    Response.Redirect "../performancedotnet/IndicesList.aspx"
    
    Code (markup):
    I'm not exactly sure of what you are trying to achieve, but I am fairly sure that you are going the wrong way about it...
     
    camjohnson95, Oct 27, 2010 IP
  5. seotraining

    seotraining Active Member

    Messages:
    511
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #5
    You can use either session or cookies or query string to pass data from one page to another
     
    seotraining, Oct 28, 2010 IP
  6. Karthik chennappan

    Karthik chennappan Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the current page should not hide and from the current asp page itself i want to read the aspx page and return the value to asp.
     
    Karthik chennappan, Oct 29, 2010 IP