ASP.NET Querystring or PopUp issue

I am working with ASP.NET, C#, and Javascript.

I need to pass information from my main page to a popup, and have the popup get the information before its opened because it uses the information I pass to populate a field.

I've passed the info on the onload of the page but it doesn't load quick enough and the box comes up empty.

I need to either use a Querystring through Javascript or create a popup window through ASP not Javascript.

Here's the code I have right now:

On my main page:

function openwindow4()
{
popUp4 = window.open("Comments.aspx","search","address=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=800, height=600, left=100, top=50,")
}

function passbackUserId()
{
var test2 = document.Form1.txtHidden2.value;
return test2;
}

function passbackQuotationId()
{
var test3 = document.Form1.txtHidden3.value;
return test3;
}



On the popUp:

<body onload="javascript:document.Form1.txtHidden.value = window.opener.passbackUserId(); document.Form1.txtHidden2.value = window.opener.passbackQuotationId();" MS_POSITIONING="GridLayout">


As you can see I popup using Javascript...how would I merge a querystring with this? Or
Can I popup using ASP {C#}?

Thanks,
weguardyou
LVL 1
weguardyouAsked:
Who is Participating?
 
dante469Connect With a Mentor Commented:
An example as promised...  Please note the datatable is populated with 200 rows...  During each row a do nothing loop is iterated 100000 per row...

Have Fun,
Dante

Once created please call the form passing the two parameters...  Something like this:

http://localhost/aspTestC/PreLoad.aspx?UserID=123&salesquotationid=321


Please create a webform containing--->

<body>
      <form id="Form1" method="post" runat="server">
            <asp:TextBox id="tb1" runat="server"></asp:TextBox><BR>
            <BR>
            <asp:DataGrid id="dg1" runat="server"></asp:DataGrid>
      </form>
</body>

Code behind as follows--->
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  string p_userid;
                  string p_salesQuotationId;
                  p_userid = Request["userId"];
                  p_salesQuotationId = Request["salesQuotationId"];
                  string userId = p_userid;
                  string salesQuotationId = p_salesQuotationId;

                  dg1load(userId, salesQuotationId);
            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.tb1.TextChanged += new System.EventHandler(this.tb1_TextChanged);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void dg1load(string uid,string qid)
            {
                  DataTable dt = new DataTable("results");
                  
                  dt.Columns.Add("UserID");
                  dt.Columns.Add("QuoteID");
                  dt.Columns.Add("column1");

                  DataRow newRow;

                  //load it into the dataTable
                  for(int s=0;s<200;s++)
                  {
                        newRow = dt.NewRow();
                        newRow["UserID"] = uid;
                        newRow["QuoteID"] = qid;
                        newRow["column1"] = s;
                        dt.Rows.Add(newRow);
                        for(int i=0;i<100000;i++)
                              i = i;
                  }
                  dg1.DataSource=dt.DefaultView;
                  dg1.DataBind();

            }
0
 
david251Commented:
Why don't you try something like this

function openwindow4()
{
popUp4 = window.open("Comments.aspx?test2=" + document.Form1.txtHidden2.value +"&test3=" + document.Form1.txtHidden3.value,"search","address=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=800, height=600, left=100, top=50,")
}

-David251
0
 
weguardyouAuthor Commented:
I tried this:

popUp4 = window.open("Comments.aspx?userId=" + test2 + "salesQuotationId=" + test3,"search","address=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=800, height=600, left=100, top=50,")

It didn't work, let me try yours...

weguardyou
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
weguardyouAuthor Commented:
No, that didn't work either...it might work but it's not getting to the popup quick enough.

the userId and the salesQuotationId are required on the popup to fill in a comment box. I can save the comments but when i open the box again the comments are not showing up. they are in the database, but it's not getting the info quick enough to populate the box.

weguardyou
0
 
_TAD_Commented:



Take your script out of the HTML page and put it in your code-behind.... just remember that all of the double quotes (") you used in javascript need to be changed to single quotes(')


<Code-behind button Click... or some other event>

string str = string.Empty;

str += "<script>";
str += "window.open('Comments.aspx?userId=' + test2 + 'salesQuotationId=' + test3,'search','address=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=800, height=600, left=100, top=50'); ";
str += "</script>";

Page.RegisterClientScriptBlock("MyKey", str);
0
 
CarlosMuCommented:
Can you try this:

On the popup window:
  1.  Create a Div area with the text box
  2.  Give this div area a negative position so it will be outside the page

 create an Onload javascript that will:

   1.Take the values from the query string and load the text box.  
   2. Change the position of the Div area so it appears within the popup
0
 
_TAD_Commented:

Page.RegisterClientScriptBlock("MyKey", str);

The previous command actually executes the script, but not until the function ends.


That is, if your code looks like:

Page.RegisterClientScriptBlock("MyKey", str);

for(int i=0;i<100000;i++)
     i = i;


The for loop with execute to completion before the pop up window appears.
0
 
dante469Commented:
weguardyou,

OK...  Pretty sure understand what is happening...  Use this (or something very close to it) to open the Popup...  Please notice the ampersand & in "&salesQuotationId="....  This creates a parameter called salesQuotationId that will be available at the popup window...

function openwindow4()
{
popUp4 = window.open("Comments.aspx?userId=" + test2 + "&salesQuotationId=" + test3,"search","address=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=800, height=600, left=100, top=50,")
}

NEXT... (this is vb.net but easy port to C#)

as part of the pageload (depending on need in or out of  IF POSTBACK) do something like this...  Please note that I am setting the values of 2 textboxes for illustration purposes only...  You do whatever is needed...

        Dim p_userid As String
        Dim p_salesQuotationId As String
        If Not Request("userid") Is Nothing Then p_userid = Request("userid")
        If Not Request("salesQuotationId") Is Nothing Then p_salesQuotationId = Request("salesQuotationId")
        tb1.Text = p_userid
        tb2.Text = p_salesQuotationId

To test/debug the pageload code you can cut paste URL into browser something like this:

http://localhost/MyTest/parmpassed.aspx?userid=123&salesQuotationId=321

Have Fun,
Dante
0
 
weguardyouAuthor Commented:
CarlosMu - that won't work, i'm not using a textbox for the comments..

_TAD_ - where do I put :for(int i=0;i<100000;i++)  i = i;?
Also, my pageload for the popup was:

private void Page_Load(object sender, System.EventArgs e)
{
comments= this.FindControl( "Comments1" ) as GeneralComments;
string userId = txtHidden.Value;
string salesQuotationId = txtHidden2.Value;
CorpTool.BusinessRules.BusinessRulesSales.getSalesQuotationNotes(userId, salesQuotationId);
}

What would I change this to?

weguardyou
0
 
CarlosMuCommented:
>>CarlosMu - that won't work, i'm not using a textbox for the comments..

No problem, just create then a Div and put the comments in the innerHtml property of the Div.
0
 
weguardyouAuthor Commented:
Following Dante I tried this:

string p_userid;
string p_salesQuotationId;
p_userid = Page.Request.QueryString("userId");
p_salesQuotationId = Page.Request.QueryString("salesQuotationId");
string userId = p_userid;
string salesQuotationId = p_salesQuotationId;
CorpTool.BusinessRules.BusinessRulesSales.getSalesQuotationNotes(userId, salesQuotationId);

I am assuming I'm using the Page.Request wrong...

weguardyou
0
 
dante469Commented:
Two things....

1) The p_userid = Page.Request("userId"); will generate an error if no value is passed for userid since a string can not = nothing

2) Pretty sure you do not need the .QueryString since it returns a collection...  Please try...
p_userid = Page.Request("userId");
p_salesQuotationId = Page.Request("salesQuotationId");

Have Fun,
Dante

0
 
weguardyouAuthor Commented:
z:\Comments.aspx.cs(39): 'System.Web.UI.Page.Request' denotes a 'property' where a 'method' was expected

When I tried p_userid = Page.Request("userId");

weguardyou
0
 
dante469Commented:
Correct C# syntax is....

p_userid = Request["userId"];
p_salesQuotationId = Request["salesQuotationId"];

Have Fun,
Dante
0
 
weguardyouAuthor Commented:
Dante,

Thanks, syntax worked but it still didnt pass the info quick enough...the SQL query is coming up as and userId = ""

Any other ideas?

weguardyou
0
 
dante469Commented:
weguardyou,

Don't understand the quick enough concept....  Assuming the query is running as part of the codebehind on the poped up form...  Since you are setting these values in codebehind simply don't call the SQL query until after set...  ie...

page load event

string p_userid;
string p_salesQuotationId;
p_userid = Request["userId"];
p_salesQuotationId = Request["salesQuotationId"];
string userId = p_userid;
string salesQuotationId = p_salesQuotationId;

//Assuming this next line runs the query....  If that is the case then certainly the parms have been set...
CorpTool.BusinessRules.BusinessRulesSales.getSalesQuotationNotes(userId, salesQuotationId);

Have re-read question several times and may not fully understand.....

R U saying that you want a webform (main) to popup a form (child)...  Have the child do something and then pass information back to main all before main renders???  Please let me know if that is the case...
0
 
dante469Commented:
Where does the SQL statement run ????

Dante
0
 
weguardyouAuthor Commented:
Datnte,

You've got it right. The pageload event needs to populate userid and quotationid.
The SQL is set in the .getsalesquotationnotes

it looks like this:

return executeQuery(      userId,CorpTool.Names.Tables.SalesQuotation.GetSalesQuotation().getSQLSelectNotes(userId,salesQuotationId ), CorpTool.Names.Tables.SalesQuotation._TableName );

The set works because I can see the comments in the database, the get is just not getting userid, etc, quick enough when it renders the popup so the comment section is blank.

weguardyou
0
 
weguardyouAuthor Commented:
public String getSQLSelectNotes( String userId, String salesQuotationId )
            {
                  return String.Format(
                        "Select CustomerNotes      as "  + CustomerNotes.AliasName    + ", "  +
                        "       InternalNotes      as "  + InternalNotes.AliasName    + "  "  +
                        "  from SalesQuotation " +
                        " Where SalesQuotationId = {0} ",
                        salesQuotationId
                        );
            }

weguardyou
0
 
_TAD_Commented:
weguardyou>

I think what you really want to do is pre-render your page, or pass an object to it that already contains all of the pertinent information.

Instead of passing parameters to the page, having the page execute SQL and display the result (all while it is loading the page), I think it you'll probably want to run the query in your main page and load a hashtable or dataset with the data and then pass that object to your child page and use that data to render your page.


anything less than that and you are talking about making database queries during the page rendering process and I don't think you'll ever be real happy with that
0
 
dante469Commented:
weguardyou,

I have read and re-read the questions and proposed answers and do not see the complexity...

You have a query that either runs on the mainform or the subform...  Either way both have the  userId and salesQuotationId in plenty of time to execute a query, return results before the page renders.  I do it all the time:)....

What I understand is you have a mainform...  The mainform knows  userId and salesQuotationId in plenty of time because it is passing it to the subform.

Mainform generates a popup form child passing userId and salesQuotationId that are resolved by the mainform while still at the server...  WELL BEFORE RENDERING EVER STARTS!!!

I routinely have a mainform that opens a child for editing detail.  Prior to rendering the child I run database functions and populate various fields well before the user ever sees the form...

I do this all the time!!!

I will send a code snippted illustrating the ASP pageload is completed before the page ever begins to render.

Please let me know how I can help,

Dante
0
 
dante469Commented:
Please let me know if I can be of any assitance in the future :)...

Good luck with all your projects!!!

Have Fun,
Dante
0
 
weguardyouAuthor Commented:
Dante,

Thank you very much!

weguardyou
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.