Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:09:49+00:00 2026-06-18T10:09:49+00:00

I have an aspx page (mainpage), that I use to populate some divs on

  • 0

I have an aspx page (mainpage), that I use to populate some divs on another aspx page (popup) on button click using the window.loaded event. Code is below:

Script on mainpage.aspx

  <script type="text/javascript">

      window.callback = function (doc) {

          if (document.getElementById('GridView2') != null)
          {
              // Get Gridview HTML and wrap it with <table> tag
              var temp = document.getElementById('GridView2').innerHTML;
              var temp2 = "<table>" + temp + "</table>";

              doc.getElementById('foo').innerHTML = temp2; // this works fine
          }
          else
          {
              // GridView is missing, do nothing!
          }
      }

      function openWindow() {

          // Only open a new Compose Email window if there is a Gridview present
          if ((document.getElementById('GridView2') != null)) {
              var mywindow = window.open("Popup.aspx");
          }
          else {
              alert("Please create GridView first");
          }
      }

Code on Popup.aspx

    <script type="text/javascript">
    function loaded() {
        window.opener.callback(document);
        alert(document.getElementById('foo').innerHTML); //This alerts the code I need

        //var input = document.createElement("input");
        //input.setAttribute("type", "hidden");
        //input.setAttribute("name", "testinput");
        //input.setAttribute("runat", "server");
        //input.setAttribute("value", document.getElementById('foo').innerHTML);

        ////append to form element that you want .
        //document.getElementById("foo2").appendChild(input);
    }
</script>

<asp:Button OnClick="Send_Email_Button_Click" ID="SendEmail" Text="Send Email" CssClass="Button1" runat="server" />
            <div id="foo" runat="server">

            </div>

Popup.aspx.cs

protected void Send_Email_Button_Click(object sender, EventArgs e)
{
    string subject = String.Format("TEST EMAIL");
    string mailto = "me@mysite.com";
    string mailfrom = Environment.UserName + "@mysite.com";
    string mailBody = "<h1>Testing</h1>";

    MailMessage mail = new MailMessage(mailfrom, mailto, subject, null);
    mail.IsBodyHtml = true;
    mail.Body = mailBody;
    SmtpClient smtpClient = new SmtpClient("smtphost");
    smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
    try
    {
        smtpClient.Send(mail);
    }
    catch (Exception ex)
    {

    }
}

Now, I’m stuck trying to pass the value of the div.innerhtml to codebehind, so I can create an email with this HTML markup. I tried using a hidden div, but I got an asp.net error about Request Validation: html code in an input field, which is a fair point. I can’t seem to access div.InnerHtml. I get the value “\r\n\r\n”. I have the value I need, but it’s in Javascript, I just need a way to get this value to C# so I can send an email.

When I click on the SendEmail button, I get the alert again (because window.loaded is being called). How can I make it so that the Popup.aspx is only populate once, and not at every button click? And how to pass the innerhtml value to get SendEmail to work? Thanks so much for looking.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:09:50+00:00Added an answer on June 18, 2026 at 10:09 am

    To send some data to code behind you have two methods. The Post and the Get.

    The one is to send data with post back – meaning that you need to add them inside a hidden or other input control that send them with post.

    The other is to add them to the url, as parameters.

    Both of this methods can be used with ajax call. So select one and send your data to code behind.

    About the message:

    Request Validation: html code in an input field
    

    This is security measure for general purpose, in your case if you know that you going to send html code on code behind, and you know how you control that, simple disabled it and do not worry – just be careful what you going to render later.

    From MSDN Request Validation in ASP.NET:

    This can be a problem if you want your application to accept HTML
    markup. For example, if your site lets users add comments, you might
    want to let users perform basic formatting using HTML tags that put
    text in bold or italics. In cases like these, you can disable request
    validation and check for malicious content manually
    , or you can
    customize request validation so that certain kinds of markup or script
    are accepted

    Update

    example code that works:
    Main page

    <head runat="server">
        <title></title>
    
        <script type="text/javascript">
          window.callback = function (doc) {
                doc.getElementById('SendBack').value = escape("<b>send me back</b>"); 
          }
    
          function openWindow() {
                var mywindow = window.open("Page2PopUp.aspx");          
          }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <a href="#" onclick="openWindow();return false">open pop up</a>
        </form>
    </body>
    </html>
    

    PopUp Page

    <head runat="server">
        <title></title>
       <script type="text/javascript">
        function GetDataBack() {
            window.opener.callback(document);
        }
    </script>
    </head>
    <body >
        <form id="form1" runat="server">
        <div>
            <input id="SendBack" name="SendBack" value="" type="hidden" />    
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" OnClientClick="GetDataBack()" />    
            <asp:Literal runat="server" ID="txtDebugCode"></asp:Literal>    
        </div>
        </form>
    </body>
    </html>
    

    and read it :

    protected void Button1_Click(object sender, EventArgs e)
    {
        txtDebugCode.Text = Server.UrlDecode(Request.Form["SendBack"]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that creates a graph on another aspx page. Sometimes
I have an aspx page with a few textboxes and a submit button. Once
I have an ASPX page with two RequiredFieldValidator and a button to go to
I have a aspx page that has a UpdatePanel and a asp timer. the
I have a .aspx page that loads three separate .ascx controls to represent adding,
I have a aspx page (details page) that needs to be loaded in a
I have a search page that uses jQuery to populate a table with search
Im in a page mainpage.aspx in which i have this code: <a rel=facebox href=destination.htm?path=blabla>mainpage</a>
I have a hidden variable in my aspx page i.e mainpage.aspx <asp:HiddenField runat=server id=hdnCommonvCode
I have an Aspx page with no .cs file. This page is using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.