forum

Home / DeveloperSection / Forums / Page_Load events fires infinity times

Page_Load events fires infinity times

Anonymous User 1675 14-Nov-2014

I have problem with my iframe asp.net page. Browser url containst parameter which I need to use in my iframe page. Obviously I can't get access via .NET so I came up with the idea that at the end of the Page_Load method add sth like that :

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bool isReloaded = Request.QueryString.GetValue<bool>("reloaded");
            ContentId = Request.QueryString.GetValue<int>("contentId"); //I need this value
            if (!isReloaded)
            {
                StringBuilder js = new StringBuilder("<script language='javascript'>");
                js.Append("var last = window.top.location.href.substring(window.top.location.href.lastIndexOf('/') + 1, window.top.location.href.length); ");
                js.Append("window.location.href = window.location.href + '?reloaded=true&contentId=' + last;");
                js.Append("if(window.location.href.indexOf('reloaded=true') == -1) window.location.reload();");
                js.Append("<" + "/script>");
                Response.Write(js.ToString());
            }
        }
    }

In shortcut I use Javascript to get value I need and fire reload() but with changed QueryString.

Page_Load is firing again and now I have bool isReloaded filled with true. The condition (!isReloaded) blocks that this time javascript will not be added to Response. I don't know why, but Page_Load fires again, this time without added parameters so it's the same situation as at the beginning and again is adding JS etc.

Result is that Page_load fires endlessly. What did I do wrong ? What is the reason ?


Updated on 14-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By