inject aspx code to javascript or how to reach postback in javascript?

Hi;

I am trying to reach postback in front in javascript and inject the given html

<asp:PlaceHolder ID="myPlaceholder" runat="server">

<script type="text/javascript">
    
    if(<%= Page.IsPostBack()%>) /// Fails here
    {
        document.write("<!DOCTYPE html>");
        document.write("<html>");
        document.write("<head>")
        document.write("<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>");
        alert("postback");
    }

Open in new window


or how can i reach postback in front?

I also add the Client register code but failed to operate it..

Regards.
LVL 12
jazzIIIloveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
Try this:
var postback ='<%= Page.IsPostBack%>';
if(postback=='True') /// Fails here
{
   alert("postback");
 }

Open in new window

0
Miguel OzSoftware EngineerCommented:
For a pure javacript solution (No server variables required)
<script type="text/javascript">
 function isPostBack()
 {
  return document.referrer.indexOf(document.location.href) > -1;
 }

 if (isPostBack()){
  //Your code goes here  
  alert("postback");
}

Open in new window

0
jazzIIIloveAuthor Commented:
Hi guru_sami;

The thing is that the code works but once it is postback, it's already too late that i cannot set DOCTYPE. Is there a way for this?

<script type="text/javascript">

    var postback = '<%= Page.IsPostBack%>';
    alert(postback);
    if (postback == 'True')
    {
        document.write("<!DOCTYPE html>");
        document.write("<html>");
        document.write("<head>")
        document.write("<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>");       
    }
   

Open in new window

0
jazzIIIloveAuthor Commented:
mas_oz2003:
Same for you too.

Guys, the thing is i have an if check in codebehind, if it's not postback, i have to set to the doctype to another type.

That's the reason of this hassle.

Regards.
0
guru_samiCommented:
Do you want to change the doctype or just add a meta tag?
If you want to change docType check this.
To just add metatag you can add this in your Page_Load:
        if (Page.IsPostBack)
        {
            HtmlMeta metaTag = new HtmlMeta();
            metaTag.HttpEquiv = "X-UA-Compatible";
            metaTag.Content = "IE=edge,chrome=1";
            Header.Controls.Add(metaTag);
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.