|
You can never get the data on page load the first time around if this is the same page where the data is assigned. Try this some combination of the below:
protected void mBtnAssignWhatever_Click(object sender, EventArgs e){
...Assign Session Variables
PopulateForm();
}
protected void PageLoad(...){
LoadDataFromDatabase();
if(!IsPostBack){
}
PopulateForm();
}
private void PopulateForm(){
if(AreMySessionVariablesAvaiable()){
...
}
else{
...
}
}
|
|
|
|
|
Ok I see where you are going with this.
I may not be able to do what I need. Because I need to load the data from the database BASED on the session variables. ("SELECT * FROM Blah WHERE FY=<session variable=""> AND JUR=<session variable="">").
Your example above loads from the database first. I would think of pulling all the data and then filtering based on the session variables but that is a TON of data to pull.
Can you think of anything other than session variables to use? I was using QueryStrings but didn't really want to go back to that. I might have to though.
|
|
|
|
|
Try the following in your Data load event:
if(SessionDataIsLoaded()){
LoadData(sessionValue, ...);
}
else{
LoadData(defaultValue, ...);
}
|
|
|
|
|
Are you talking about the datalist Init event? Because I do not even begin to call anything that pulls data without having the session variables first.
|
|
|
|
|
|
So...I have decided to use PayPal. To my surprise, there is apparently no smooth way to use a PayPal form button on an ASP.net page. OK....so I create a HTML page with the button on it and I insert it into the website. When the user hits Submit from ASP.Net, it enters all the data into the database and then brings up the HTML page with the button....and that works fine. However, I want to post the generated Customer ID number for the customer so that when he returns to the site with proof of purchase from PayPal, I can identify him in the database. What I need to do is have the ID, which was generated by a script on the ASP.Net page, pass that information to the HTML page into a label along side the PayPal button so the customer can write it down and use it with his proof of purchase (invoice) from PayPal. If I was using ASP to ASP, I would simply create a Session value and that would be the end of it. But how do I get the value from the ASP page to the HTML page? Any insight or an example would be greatly appreciated. Thank you, Pat
ps: I may have accidentally posted this into another place on this site. It was not an INTENTIONAL double entry. For those purists that cannot deal with a simple mistake, I apologize in advance and hope that the extra entry doesn't ruin their day.
|
|
|
|
|
Why did you create an HTML page instead of an ASP.NET page? ASP.NET now supports multiple form tags in a page (kinda) which will allow you to use ASP.NET to populate your form as you are familiar and then post to the PayPal site.
|
|
|
|
|
Did you try a google search for paypal asp.net? While there are 2.3 million results to sort through, several on the first page looked very promising.
|
|
|
|
|
Thank you, Mr. Gray and Mr. Lynch. I am sure that since the article I read was written, there is some kind of ASP.Net solution. I like ASP.Net and prefer it, but as a developer, the first think I learned is not to swim against the tide. I think PayPal is foolish for not creating a streamlined solution for this issue, however, that's their deal. Mine is to make it work as simply and effectively as possible. I therefore have decided to use a simpler integrated solution that uses both ASP and HTML pages. For others looking in, I use ASP first to get the data into the database, then use it again to show the customer the information I need him to have. Then, I go to HTML to host the PayPal button, which was written for HTML. It looks good (enough) and works perfectly, which is most important, so I am going to stay with it, at least for now. I appreciate the input from both of you. Thank you and best regards, Pat
|
|
|
|
|
Hi,
My website shows a sessiontimeout page when some event happens on a page and the the sesssion is expired.
All Page inherits from sessionmanagement class
In the init function of sessionmanagement class, in case the session is expired, it redirects page to sessiontimeout.htm which is in the same folder as response.redirect("sessiontimeout.htm")
For main.aspx it works fine, shows sessiontimeout.htm fine.
main.aspx has ajaxtabcontainer and each tab has iframe.
The pages in the iframe are also inherited from sessionmanagement class.
In case session expires and any event happens in the pages in the iframe, it tries to load sessiontimeout.htm but gives error -400.
I checked the properties in browser. To my surprise, it was trying to load as
<base url="" />/<base root="" folder="" again="" />/sessiontimeout.htm
e.g. if my baseurl is http://myserver/mysite it was trying to load as http://myserver/mysite/mysite/sessiontimeout.htm
I dont know why it was appending the base root folder again.
Why it is giving this strange behaviour from pages in iframe when all the pages are in the same folder?
I guess for this application, this was not happening in visual studio 2008 but now I am using visual studio 2010.
Any suggestions?
Thanks
Vijay
|
|
|
|
|
|
I have a masterpage called CaseManagement.Master and a content page called AppointmentSchedule. On my master page I have a textbox called txtPolicyNumber. How do I access this textbox from the content page's codebehind? "this.txtPolicyNumber" and "this.Master.txtPolicyNumber" doesn't work.
|
|
|
|
|
you acn access controls of master page like this
TextBox tb = (TextBox)Master.FindControl("txtPolicyNumber");
|
|
|
|
|
You can expose it as a property. This is more efficient than using FindControl since it won't have to search through the control heirarchy.
public String MyTextBox
{
get
{
return txtPolicyNumber.Text;
}
set
{
txtPolicyNumber.Text = value;
}
}
|
|
|
|
|
Hi,
I try to import Excel files to sqlserver problem is that the number and the titles of columns are dynamic.How can i do that?by code.
Thank you
|
|
|
|
|
Do you want a new table each time? You could use a select into SQL statement.
What are you going to do with the data? A bunch of random SQL tables with random columns doesn't sound very useful.
|
|
|
|
|
thank you T M Gray,
I have this problem for almost a month.
I work on an intranet site management reviews of students.
I want to help the manager module to enter student markes .
the problem is that the subjects of a module are dynamic ,I tried a gridview in edit mode but I failed to create the columns dynamically and insert all data at once in the DB.
Now I have an excel file generated by a dynamic sql query containing students of a module but I do not know how import it to the database because the column names and number change .
the table:
reveiw :
id_student________id_subjects______marks
table subject:
id_subject_______name_subject______id_module
the excel file columns:
id_student_____name_student_____name_subject1____name_subject2....
in the name_subjet1 i have de marks of subject1.
I do not know what to do ,is there another solution?
Thanks.
|
|
|
|
|
It looks to me like you need to redo the query that generates the excel file.
The relationships between student, subject, and module aren't completely clear to me.
|
|
|
|
|
Hi,
this is the query that generates excel:
DECLARE @MATIERE nvarchar(max) <br />
SELECT @MATIERE = <br />
STUFF( <br />
( <br />
select distinct ',[' + LIBELLE_MATIERE + ']' <br />
from MATIERE where CODE_MODULE =11 <br />
for xml path('') <br />
), <br />
1,1,'') <br />
<br />
DECLARE @SQL nvarchar(max) <br />
SELECT @SQL = N' <br />
select <br />
* <br />
from ( <br />
<br />
SELECT ETUDIANT.NUM_INSCRIPTION, ETUDIANT.NOM_PRENOM_ETUDIANT_ARABE,EXAMEN.CODE, <br />
EXAMEN.NOTE, <br />
MATIERE.LIBELLE_MATIERE <br />
FROM ETUDIANT INNER JOIN <br />
EXAMEN ON ETUDIANT.NUM_INSCRIPTION = EXAMEN.NUM_INSCRIPTION INNER JOIN <br />
CAPITALISE_MODULE ON <br />
ETUDIANT.NUM_INSCRIPTION = CAPITALISE_MODULE.NUM_INSCRIPTION INNER JOIN <br />
MATIERE ON EXAMEN.CODE_MATIERE = MATIERE.CODE_MATIERE INNER JOIN <br />
MODULE ON CAPITALISE_MODULE.CODE_MODULE = MODULE.CODE_MODULE <br />
AND MATIERE.CODE_MODULE = MODULE.CODE_MODULE <br />
WHERE (CAPITALISE_MODULE.CODE_MODULE = 11) AND <br />
(CAPITALISE_MODULE.CODE_TYPE_RELATION_MODULE = 1) <br />
) Data <br />
PIVOT ( <br />
SUM(NOTE) <br />
FOR LIBELLE_MATIERE <br />
IN ( <br />
' + @MATIERE + ' <br />
) <br />
) PivotTable <br />
' <br />
<br />
exec sp_executesql @SQL <br />
there is a relationship"review" between the student and subject
and a relationship between subject and module(module consists of several materials)
Thanks.
|
|
|
|
|
Hy,
I have a reuirement in which i have to send a mail.The mail would have two parts.Confirm and Deny.
I have to pass 2 links to confirm and deny which the user can not see. so that when he click on confirm,a link should open directly.
And the link should not be shown to the user.
Thanks nad Regards,
raghvendra Panda
|
|
|
|
|
I don't believe you will be able to hide the link. If you are sending a HTML formatted email, the user could always do a "view source" and see the link.
Explain in more detail what you are trying to achieve and maybe we can give you a different approach.
For example, you can have a link that passes a parameter to a webpage and that parameter represents either confirm or deny. The value of the parameter would be some hash algorithm of the email and a datetimestamp, so that the link would expire after a number of days.
A table on the server would be something like:
EmailTo, LinkCreationDateTime, HashValueConfirm, HashValueDeny, ResponseDateTime, ResponseValue (Deny or Confirm)
Here is how it would work:
When you send the email, create a record in this table with the EmailTo, the current timestamp, a has value which represents Confirm and a Hashvalue which represents Deny.
When the user receives the email, he can click on either the Confirm or Deny link, which will pass the appropriate hash value.
When the link is processed at the server, it will first check to see if there is a value in the ResponseValue for this user, if there is already a value, then ignore this new link response. If there is no value, check the value of the hash against the HashValueConfirm and HashValueDeny and set the appropriate ResponseValue.
Hope this gives you something to think about.
|
|
|
|
|
Hello every1.
I am trying to improve my skill in ASP.net with C# code. I use MVC in this sample. I create a database and trying to insert data by using Storedprocedure. I created an SP in SQL and wana use it. the problem is I don't know how to use it. I write some code but I really don't know what is the next step. Could you please help me??
it is the first class:item
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace MvcApplication1.Models.Repository.DTO
{
public class Item
{
//definition of class's fileds
public int _id;
public int _code;
public string _description;
public string _creator;
public DateTime _created;
//definition of properties
public int Id
{
set
{
_id = value;
if (value < 0)
throw new ArgumentException(string.Format("Id should be greater than 0 !"));
}
get { return _id; }
}
public int Code
{
set { _code = value; }
get { return _code; }
}
public string Description
{
set { _description = value; }
get { return _description; }
}
public string Creator
{
set { _creator = value; }
get { return _creator; }
}
public DateTime Created
{
set { _created = value; }
get { return _created; }
}
//definiton of constructor
public Item(int id, int code, string description, string creator, DateTime created)
{
this._id = id;
this._code = code;
this._description = description;
this._creator = creator;
this._created = created;
}
}
}
the next class is as below
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using MvcApplication1.Models.Repository.DTO;
namespace MvcApplication1.Repository
{
public class ItemRepository
{
//definition of fields
private const string datasource =
"Data Source= Dell\\SQLEXPRESS;Initial Catalog=DB_Furniture.mdf;Integrated Security=True;User Instance=True";
private SqlConnection _connection;
private SqlDataAdapter _dataAdapter;
private DataSet _dataset;
private SqlCommand _sqlcommand;
//definition of constructor
public ItemRepository()
{
// instantiate the connection
_connection = new SqlConnection(datasource);
// instantiate a new DataSet
_dataset = new DataSet();
_dataAdapter = new SqlDataAdapter(_sqlcommand);
//definition of SQl SP parameters
_sqlcommand.CommandType = CommandType.StoredProcedure;
_sqlcommand.Parameters.Add("@Code", SqlDbType.NVarChar);
_sqlcommand.Parameters.Add("@Description", SqlDbType.NVarChar);
_sqlcommand.Parameters.Add("@Created", SqlDbType.NVarChar);
_sqlcommand.Parameters.Add("@Creator", SqlDbType.NVarChar);
what is next?????????????????????????????????????????????????????????????
how shold i call SP ?????
}
}
}
|
|
|
|
|
First: Might want to tidy that up a bit, you're not quite using code blocks right.
Second: You're almost there, the first class doesn't come into it. You've defined the connection object, the command object so just set the command's ".CommandText" to be your stored procedure name, ".Connection" to be your connection and then open the connection and execture the command using .ExecuteNonQuery, .ExecuteReader, .ExecuteScalar, etc. depending on what return, if any, you want.
|
|
|
|
|
thx for reply,
Could you please advice me how can I make it more tidy.
the next question is how assign the value of textboxes to them. I mean how pass the parameter to SP?
Could you please give me an example.
thx in advance
|
|
|
|
|
Well putting only the code relevant into "pre" tags would be a help.
Anyway, you've added the parameters a bit wrong, you've supplied the name and the type not the value which would be your textboxes.
I'm not going to give direct code snippets as you should be able to work from the words I'm giving you, otherwise the next time you have to do this again, it won't have registered and you wont understand what you did previously.
|
|
|
|