Solved

ASP.NET Querystring or PopUp issue

Posted on 2004-03-31
23
2,106 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:weguardyou
  • 9
  • 8
  • 3
  • +2
23 Comments
 
LVL 19

Expert Comment

by:david251
ID: 10724081
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
 
LVL 1

Author Comment

by:weguardyou
ID: 10724112
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
 
LVL 1

Author Comment

by:weguardyou
ID: 10724138
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
 
LVL 22

Expert Comment

by:_TAD_
ID: 10724227



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
 
LVL 6

Expert Comment

by:CarlosMu
ID: 10724243
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
 
LVL 22

Expert Comment

by:_TAD_
ID: 10724244

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
 
LVL 7

Expert Comment

by:dante469
ID: 10724354
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
 
LVL 1

Author Comment

by:weguardyou
ID: 10724377
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
 
LVL 6

Expert Comment

by:CarlosMu
ID: 10724420
>>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
 
LVL 1

Author Comment

by:weguardyou
ID: 10724455
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
 
LVL 7

Expert Comment

by:dante469
ID: 10724652
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:weguardyou
ID: 10724687
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
 
LVL 7

Expert Comment

by:dante469
ID: 10724715
Correct C# syntax is....

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

Have Fun,
Dante
0
 
LVL 1

Author Comment

by:weguardyou
ID: 10724762
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
 
LVL 7

Expert Comment

by:dante469
ID: 10724959
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
 
LVL 7

Expert Comment

by:dante469
ID: 10724968
Where does the SQL statement run ????

Dante
0
 
LVL 1

Author Comment

by:weguardyou
ID: 10725042
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
 
LVL 1

Author Comment

by:weguardyou
ID: 10725062
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
 
LVL 22

Expert Comment

by:_TAD_
ID: 10725309
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
 
LVL 7

Expert Comment

by:dante469
ID: 10726208
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
 
LVL 7

Accepted Solution

by:
dante469 earned 500 total points
ID: 10726571
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
 
LVL 7

Expert Comment

by:dante469
ID: 10726691
Please let me know if I can be of any assitance in the future :)...

Good luck with all your projects!!!

Have Fun,
Dante
0
 
LVL 1

Author Comment

by:weguardyou
ID: 10727605
Dante,

Thank you very much!

weguardyou
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now