Answered by:
Passing Information from user session

Question
-
User-1994446809 posted
I have two webforms (Default1.aspx and Default2.aspx). The Default.aspx has a label that represents login ID, and on the Default2.aspx, there is an input box like this
Default.aspx
<a><asp:Label ID="user" runat="server" Font-Size="Medium" Text="" ForeColor="White"></asp:Label></a>
Default2.aspx
<input type="email" runat="server" id="email-address" required />
And I want to pass information from user session into the input box in Default2.aspx. I don’t know if it can be done though, but I used this;
The yellow highlighted area is used as the input ID because the javascript event which i am using from an external gateway has "email-address" fixed as the ID as shown below. So i want to pass information into the input having the same ID as the input, because having a different ID from the above input will not load the script.
email: document.getElementById("email-address").value,
Default2(Code behind)
protected void Page_Load(object sender, EventArgs e) { con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"; { email-address.Text = Session["user"].ToString(); } }
May i please what should be done to achieve the goal?
Saturday, May 30, 2020 9:41 PM
Answers
-
User288213138 posted
Hi georgeakpan233,
May I please ask if you did change the ID in the java and it worked in your computer?document.getElementById("email-address").value,
I haven't tested all your code, but you can get the value of the input through this method.
document.getElementById("userid").value,
So I suggest you use F12 to debug your js code to see if payWithPaystack is triggered and if there is an error message in the console.
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 5, 2020 3:24 AM
All replies
-
User-2054057000 posted
So i want to pass information into the input having the same ID as the input, because having a different ID from the above input will not load the script.You can have same Id of controls as long as controls are in different pages. Session data can be easily shown in these controls.
What errors you are getting in achieving this??
Sunday, May 31, 2020 2:55 PM -
User-1994446809 posted
Here is my .aspx web form code
<div class="container-fluid"> <div class="content"> <div class="header"> <h4 class="title">Payment Page</h4> </div> <div class=""> <script src="https://js.paystack.co/v1/inline.js"></script> <div class="form-group"> <label for="email">Email Address</label> <input type="email" runat="server" id="email-address" required /> <br /> </div> <div class="form-group"> <label for="amount">Amount</label> <input type="tel" id="amount" required /> <br /> </div> <div class="form-group"> <label for="first-name">First Name</label> <input type="text" id="first-name" /> <br /> </div> <div class="form-group"> <label for="last-name">Last Name</label> <input type="text" id="last-name" /> <br /> </div> <div class="form-submit"> <button type="button" id="Button1" runat="server" class="btn btn-primary navbar-btn" onclick="payWithPaystack()">Deposit</button> </div> </div> </div> </div>
The yellow highlighted area is the input box with identifier as email-address. Then this is what I used in the server side code (code behind)
protected void Page_Load(object sender, EventArgs e) { con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"; { email-address.Text = Session["user"].ToString(); } } }
Then I am getting this error:
'email-address' is not a valid identifier.
below is a link to the error
Sunday, May 31, 2020 3:14 PM -
User-2054057000 posted
'email-address' is not a valid identifier.You have to change the name to something like 'emailAddress' because such names having '-' between then is not valid.
Sunday, May 31, 2020 6:37 PM -
User409696431 posted
'email-address' is not a valid identifier.
"Only combinations of alphanumeric characters and the underscore character ( _ ) are valid values for this property. Including spaces or other invalid characters will cause an ASP.NET page parser error."
You won't be able to use that ID, even though you added runat="server" to the <input> tag. You need to re-think your design. Perhaps load a hidden field with the value and use JavaScript to add the value to the input tag.
Sunday, May 31, 2020 6:43 PM -
User-1994446809 posted
I did change the name to "userid", but it did not rhyme with with the identifier of the popup for that is used to pass information to.
The information passed doesn't just stop there, it also goes to a popup form which is a javascript function; and this javascript popup form is an initialization of payment gateway where the identifier has already been set.Sunday, May 31, 2020 7:08 PM -
User-1994446809 posted
Adding runat="server" to the <input> tag was a mistake.
"Perhaps load a hidden field with the value and use JavaScript to add the value to the input tag." How is this done please?Sunday, May 31, 2020 7:11 PM -
User288213138 posted
Hi georgeakpan233,
Adding runat="server" to the <input> tag was a mistake.
"Perhaps load a hidden field with the value and use JavaScript to add the value to the input tag." How is this done please?If you want to set the text displayed in the input, then you can use the value attribute.
<input type="email" runat="server" id="userid" required="required" /> protected void Page_Load(object sender, EventArgs e) { userid.Value = "aaa"; }
Or you can try to use the TextBox control.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> protected void Page_Load(object sender, EventArgs e) { TextBox1.Text = "aaa"; }
Best regards,
Sam
Monday, June 1, 2020 5:51 AM -
User-1994446809 posted
Hi Samwu,
<input type="email" runat="server" id="userid" required="required" /> protected void Page_Load(object sender, EventArgs e) { userid.Value = "aaa"; }
Using identifier as userid, the gateway javascript doesn't load. If I change the id to "email-address" without passing any information to it; and the information is inserted manually into the <input> tag, the javascript loads (opens up payment gateway javascript)
Monday, June 1, 2020 9:33 AM -
User288213138 posted
Hi georgeakpan233,
Using identifier as userid, the gateway javascript doesn't load.Is there any error message? Please show me your javascript code.
Best regards,
Sam
Tuesday, June 2, 2020 2:50 AM -
User-1994446809 posted
Thank you samwu,
samwu
Is there any error message? Please show me your javascript code.On my home web form there is a label that displays user ID as shown below:
Home.aspx
<asp:Label ID="user" runat="server" Font-Size="Medium" Text="" ForeColor="White"></asp:Label>
And a button:
Home.aspx
<script src="https://js.paystack.co/v1/inline.js"></script> <button type="button" id="paybutton" runat="server" class="btn btn-primary navbar-btn" onclick="payWithPaystack()">Deposit</button>
When the deposit button is clicked, it redirects to the payment page where payment data is required before loading the payment gateway javascript portal for payment. The code is shown below (It is a Paystack payment gateway):
PaymentPage.aspx
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Payment</title> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <form id="paymentForm" runat="server"> <div class="container"> <h2>Modal Example</h2> <!-- Trigger the modal with a button --> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <script src="https://js.paystack.co/v1/inline.js"></script> <div class="form-group"> <label for="email">Email Address</label> <input type="email" id="email-address" required /> <br /> </div> <div class="form-group"> <label for="amount">Amount</label> <input type="tel" id="amount" required /> <br /> </div> <div class="form-group"> <label for="first-name">First Name</label> <input type="text" id="first-name" /> <br /> </div> <div class="form-group"> <label for="last-name">Last Name</label> <input type="text" id="last-name" /> <br /> </div> <div class="form-submit"> <button type="submit">Pay </button> <asp:Button ID="Button1" runat="server" Text="Button" /> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> </form> <script> var paymentForm = document.getElementById('paymentForm'); paymentForm.addEventListener("submit", payWithPaystack, false); function payWithPaystack() { var handler = PaystackPop.setup({ key: 'pk_live_8971529205020dd307b6f5f4cec944c62712066d', // Replace with your public key email: document.getElementById("email-address").value, amount: document.getElementById("amount").value * 100, firstname: document.getElementById("first-name").value, lastname: document.getElementById("first-name").value, ref: '' + Math.floor((Math.random() * 1000000000) + 1), // generates a pseudo-unique reference. Please replace with a reference you generated. Or remove the line entirely so our API will generate one for you // label: "Optional string that replaces customer email" onClose: function () { alert('Window closed.'); }, callback: function (response) { var message = 'Payment complete! Reference: ' + response.reference; alert(message); } }); handler.openIframe(); } </script> </body> </html>
From the above codes, when the “deposit” button on the home web form is clicked, it redirects to the payment page, then the user ID is expected to be passed from the home web form (“user ID label”) into the <input> tag highlighted in the yellow area. The issue is that if I change the id of the input tag to “user” in order to pass the information; it passes the information, but the payment portal (in javascript) will not load because the IDs don't match. But when the <input> tag have the same ID as the “email ID” on the javascript (as shown in the red highlighted area), it loads. This means that on the <input >tag, the email information which is the user’s ID will be inputted manually. But I would prefer to pass user ID into the input tag in order to help user’s not to mistakenly input another email address.
Tuesday, June 2, 2020 10:07 AM -
User288213138 posted
Hi georgeakpan233,
when the “deposit” button on the home web form is clicked, it redirects to the payment page, then the user ID is expected to be passed from the home web form (“user ID label”) into the <input> tag highlighted in the yellow areaWhat method did you use to pass the user ID?
The issue is that if I change the id of the input tag to “user” in order to pass the information; it passes the information, but the payment portal (in javascript) will not load because the IDs don't match. But when the <input> tag have the same ID as the “email ID” on the javascript (as shown in the red highlighted area), it loads.You changed the id in the <input> tag, do you also change it in javascript?
Best regards,
Sam
Wednesday, June 3, 2020 2:13 AM -
User-1994446809 posted
Hi Samwu,
samwu
What method did you use to pass the user ID?On the code behind Paymentpage, I used this
protected void Page_Load(object sender, EventArgs e) { con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"; user.Visible = true; if (!IsPostBack) { userid.Text = Session["user"].ToString(); } }
samwu
You changed the id in the <input> tag, do you also change it in javascript?Yes I did that too and the java did not load. I dont know if that email-address ID in the java is tied to the gateway.
Wednesday, June 3, 2020 8:19 AM -
User288213138 posted
Hi georgeakpan233,
userid.Text = Session["user"].ToString();
<input type="email" id="email-address" required />
In your code behind, you use "userid" to bind value to the input tag, but in the input tag, your id is "email-address".
Yes I did that too and the java did not load. I dont know if that email-address ID in the java is tied to the gateway.You can try to use F12 to debug your js code. about how to use F12 - Developer Toolbar you can refer to this link:
https://www.c-sharpcorner.com/UploadFile/francissvk/f12-developer-toolbar-good-rescuer/
Best regards,
Sam
Thursday, June 4, 2020 2:38 AM -
User-1994446809 posted
Hi Samwu,
In your code behind, you use "userid" to bind value to the input tag, but in the input tag, your id is "email-address".Sorry about that; I was supposed to send the method from the test project but I mistakenly sent the the one from the main project.
In the code behind, when the ID is changed to email-address, the ID "email-address is not a recognized identifier due to the "-", and it will return an error.
Here is the method used in the test project and the <inpu> tag, both with the same ID
userid.Text = Session["user"].ToString();
<input type="email" id="userid" required />
May I please ask if you did change the ID in the java and it worked in your computer?
-George
Thursday, June 4, 2020 8:13 AM -
User288213138 posted
Hi georgeakpan233,
May I please ask if you did change the ID in the java and it worked in your computer?document.getElementById("email-address").value,
I haven't tested all your code, but you can get the value of the input through this method.
document.getElementById("userid").value,
So I suggest you use F12 to debug your js code to see if payWithPaystack is triggered and if there is an error message in the console.
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 5, 2020 3:24 AM