introlux
asked on
Passing variables via ASP.Net c#
Hi,
I have 6 variables that I am needing to pass through to the next page. They are all a string type. All 6 variables are loaded into text boxes. I need these variables to pass through to the new window (new aspx page) that is opened after a button click, which will perform an action with the chosen variables.
How is this possible?
Any help will be appreciated.
Regards,
introlux
I have 6 variables that I am needing to pass through to the next page. They are all a string type. All 6 variables are loaded into text boxes. I need these variables to pass through to the new window (new aspx page) that is opened after a button click, which will perform an action with the chosen variables.
How is this possible?
Any help will be appreciated.
Regards,
introlux
Hello introlux,
As you are opening new window then the simplest method would be to include the values in the querystring of the URL used to open that new window. You can achieve this relatively easily in the javascript used to open the new window.
<script type="text/javascript">
function openNewPage() {
var baseUrl = '/mynewpage.aspx?';
var qsItem1 = 'Variable1=' + document.getElementById('< %= MyTexbox1.ClientId() %>').value;
var qsItem2 = 'Variable1=' + document.getElementById('< %= MyTexbox2.ClientId() %>').value;
var qsItem3 = 'Variable1=' + document.getElementById('< %= MyTexbox3.ClientId() %>').value;
var qsItem4 = 'Variable1=' + document.getElementById('< %= MyTexbox4.ClientId() %>').value;
var qsItem5 = 'Variable1=' + document.getElementById('< %= MyTexbox5.ClientId() %>').value;
var qsItem6 = 'Variable1=' + document.getElementById('< %= MyTexbox6.ClientId() %>').value;
var finalUrl= baseUrl + qsItem1 + '&' + qsItem2 + '&' + qsItem3 + '&' + qsItem4 + '&' + qsItem5 + '&' + qsItem6;
window.open(finalUrl);
}
Then just use onclick="openNewPage();" as the event handler in your button.
Regards,
TimCottee
As you are opening new window then the simplest method would be to include the values in the querystring of the URL used to open that new window. You can achieve this relatively easily in the javascript used to open the new window.
<script type="text/javascript">
function openNewPage() {
var baseUrl = '/mynewpage.aspx?';
var qsItem1 = 'Variable1=' + document.getElementById('<
var qsItem2 = 'Variable1=' + document.getElementById('<
var qsItem3 = 'Variable1=' + document.getElementById('<
var qsItem4 = 'Variable1=' + document.getElementById('<
var qsItem5 = 'Variable1=' + document.getElementById('<
var qsItem6 = 'Variable1=' + document.getElementById('<
var finalUrl= baseUrl + qsItem1 + '&' + qsItem2 + '&' + qsItem3 + '&' + qsItem4 + '&' + qsItem5 + '&' + qsItem6;
window.open(finalUrl);
}
Then just use onclick="openNewPage();" as the event handler in your button.
Regards,
TimCottee
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could also submit the form to a new window which would probably be the best way of handling it.
You would need to set the form target as a new window or a popup which you could generate with JavaScript.
You would then retain the viewstate etc.
You would need to set the form target as a new window or a popup which you could generate with JavaScript.
You would then retain the viewstate etc.
ASKER
My problem I am having is that I am trying to a download of a .ICS file to save in a new window. I have the question listed here:
https://www.experts-exchange.com/questions/23871381/File-download-prob-ASP-Net-c.html
As I have other functions working, everything seems to stop because of the file download. That is why I am thinking of passing the values across to a new page and then creating the .ICS file, but seems to have failed because I cannot get the page to be opened in a new window + executes the file save as dialogue box is displayed.
Regards,
introlux
https://www.experts-exchange.com/questions/23871381/File-download-prob-ASP-Net-c.html
As I have other functions working, everything seems to stop because of the file download. That is why I am thinking of passing the values across to a new page and then creating the .ICS file, but seems to have failed because I cannot get the page to be opened in a new window + executes the file save as dialogue box is displayed.
Regards,
introlux
I have answered on your other page in relation to that question.
However in relation to this, I would say the best method would probably be to change the forms target attribute to _new via JavaScript or ASP.NET code.
However in relation to this, I would say the best method would probably be to change the forms target attribute to _new via JavaScript or ASP.NET code.
ASKER
I believe this is the cleanest method.
Thanks
Thanks
ASKER
Im just trying to pass through data basically.