|
And where is the button click event? Without checking for IsPostback all this will do is repopulate the controls from the database and overwrite the value you expect.
I would refactor this code to extract the all the SQL lookup code to a method so It can be called from multiple places in your code. Such as from the PageLoad event and from the button click handler
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thank you for your help, Mark. Here is the full text:
//The Button Code
protected void ButtonGoBack_Click(object sender, EventArgs e)
{
LoadPreviousVersion();
}
//The Method Call
private void LoadPreviousVersion()
{
int requestedVersion = (int.Parse(LabelVersion.Text)) - 1;
if (requestedVersion < 1)
requestedVersion = 1;
LabelVersion.Text = requestedVersion.ToString();
if (int.Parse(LabelVersion.Text) != int.Parse(lastCompletedVersion))
ButtonEdit.Enabled = false;
else
ButtonEdit.Enabled = true;
medDate = CreateMedicalDate(medDate);
SqlConnection Conn = new SqlConnection(CONNSTR);
try
{
string Sql = "SELECT [Id],[Period] , [Screening_Number] , [Site_Number] , " +
"[Version_Id],[Version] , [Ae] , [Frequency] , [Visit] , [VisitNumber] , [Date_Onset] , " +
"[Ongoing] , [Date_Ended] , [CTCAE] , [Serious] , [Related] , [Action] , [Outcome] , " +
"[NewConMedsY], [NewConMedsN], [SubBy] , [SubOn] , [Sae_Rpt_Status] " +
"FROM Adverse_Events WHERE [Version_Id] = @Version_Id AND [Version] = @RequestedVersion ";
SqlCommand Comm = new SqlCommand(Sql, Conn);
Comm.CommandType = CommandType.Text;
Comm.Parameters.Clear();
Comm.Parameters.AddWithValue("@Version_Id", Version_Id);
Comm.Parameters.AddWithValue("@RequestedVersion", requestedVersion);
SqlDataAdapter da = new SqlDataAdapter(Comm);
DataSet ds = new DataSet();
da.Fill(ds);
LabelPeriod.Text = ds.Tables[0].Rows[0]["Period"].ToString();
LabelScreeningNumber.Text = ds.Tables[0].Rows[0]["Screening_Number"].ToString();
LabelVersion.Text = ds.Tables[0].Rows[0]["Version"].ToString();
LabelId.Text = ds.Tables[0].Rows[0]["Id"].ToString();
LabelAe.Text = ds.Tables[0].Rows[0]["Ae"].ToString();
LabelFrequency.Text = ds.Tables[0].Rows[0]["Frequency"].ToString();
LabelVisit.Text = ds.Tables[0].Rows[0]["Visit"].ToString();
LabelVisitNum.Text = ds.Tables[0].Rows[0]["VisitNumber"].ToString();
LabelDateStarted.Text = ds.Tables[0].Rows[0]["Date_Onset"].ToString();
LabelOngoing.Text = ds.Tables[0].Rows[0]["Ongoing"].ToString();
LabelDateStopped.Text = ds.Tables[0].Rows[0]["Date_Ended"].ToString();
LabelCtcae.Text = ds.Tables[0].Rows[0]["CTCAE"].ToString();
LabelSerious.Text = ds.Tables[0].Rows[0]["Serious"].ToString();
LabelRelated.Text = ds.Tables[0].Rows[0]["Related"].ToString();
LabelAction.Text = ds.Tables[0].Rows[0]["Action"].ToString();
LabelOutcome.Text = ds.Tables[0].Rows[0]["Outcome"].ToString();
RadioButtonConMedY.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["NewConMedsY"].ToString());
RadioButtonConMedN.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["NewConMedsN"].ToString());
LabelSubBy.Text = Session["Name"].ToString();
LabelSubOn.Text = medDate;
}
catch (Exception ex)
{
Console.WriteLine("Error : " + ex.Message);
}
}
|
|
|
|
|
I may be confused, both posts together are the code you are using correct? If so, then as I said, you need to use IsPostBack in the PageLoad event so the controls are not overwritten each time the page is loaded, i.e. during a postback caused by the button click. And again, abstract the database code to a separate method. It will save you a lot of typing and cut & paste errors and debugging.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes,Yes,Yes,Yes....OK....."I SEE" said the blind man. Both you and David were right Mark, and now I GET it. When the page re posts, it is running the load event all over again, and that is overwriting the method so it appears that it is unchanged. I am so sorry that I did not understand. You are both saying the same thing.....it took a moment for it to sink in. THANK YOU both very much. I scripted it a bit different, but it is working now. I will try to mark both answers correct, as they both are. If it is not allowed, I guess I will have to stamp Mark's first only since his was sent first. I greatly appreciate the time and skill from both of you, and I hope you will sign in for me again in the future. Best regards, Pat
|
|
|
|
|
PDTUM wrote: I have written a page that accepts new information and then repopulates the page when a button is clicked. This is a simple task in C#, but seems very complicated in ASP.net. The code seems to work fine on the first click, but the after the first click, the page no longer repopulates.
PDTUM wrote: This page is brought up from a click event on another page's GridView and is supposed to populate information accordingly.
Well I might be a little confused on exactly which is the first click.
But anyways what you need is code like this ...
protected void Page_Load(object sender, EventArgs e) {
if (Page.IsPostBack)
{
LabelVersion label gets deincremented here
}
medDate = CreateMedicalDate(medDate);
id = Request.QueryString["Id"];
Screening_Number = Request.QueryString["Screening_Number"];
Site_Number = Request.QueryString["Site_Number"];
and so on ...
|
|
|
|
|
Yes,Yes,Yes,Yes....OK....."I SEE" said the blind man. Both you and Mark were right David, and now I GET it. When the page re posts, it is running the load event all over again, and that is overwriting the method so it appears that it is unchanged. I am so sorry that I did not understand. You are both saying the same thing.....it took a moment for it to sink in. THANK YOU both very much. I scripted it a bit different, but it is working now. I will try to mark both answers correct, as they both are. If it is not allowed, I guess I will have to stamp Mark's first only since his was sent first. I greatly appreciate the time and skill from both of you, and I hope you will sign in for me again in the future. Best regards, Pat
|
|
|
|
|
hi, iam using asp.net with c#, with sql server 2000
in my gridview iam displaying data from view at page load event
the 1st column is checkbox in template field,2nd is categorynamee,3rd is itemkey, 4th is itemkeyname
5th is currentqty, 6th is salesprice,7th is quantity, 8th is total
i have to insert into two tables
1st table orders
orderno int primary key autoincrement,
username nvarchar(50) ,
shopname nvarchar(50),
email nvarchar(100)
2nd table is Orderdetails
serialno int primarykey autoincrement,
orderno int foreignkey,
categorynamee nvarchar(50),
itemkey nvarchar(50),
itemkeyname nvarchar(50),
currentqty decimal,
salesprice decimal,
quantity int,
total decimal
when user selects any no of the checkboxes that rows should be added in both tables, iam getting errors
can you give examples which helps me
|
|
|
|
|
So at the time of subit, Iterate throgh all the gridview rows and which row has checkbox checked, save it in database.You can save the data in both the table using query.
Where are you actually facing problem?
|
|
|
|
|
Easy, your code is wrong - what else do you expect it to be?
Without seeing your code or knowing what errors you are getting someone is meant to help you fix the problem. Can you see where the problem really lies?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
What errors are you getting?
developerit wrote: can you give examples which helps me
Search google, you'll find many examples on this.
|
|
|
|
|
Hi,
I have the following problem:
Two custom controls, first control has a button, when I click this button I'd like to render the second custom control content in popup window. How to do it?
Please, help.
|
|
|
|
|
So what is the problem, have a page with second custom control and on button click open that page in popup. You can also use ajaxmodelpopupextender.
|
|
|
|
|
You can use the AjaxControlToolkit to perform this action.
|
|
|
|
|
I would like to call some methods at the very beginning of my web application. Also, I want to ensure that those methods are called only once per application lifetime, no matter what. What is the best way to accomplish this?
|
|
|
|
|
TRY THIS
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
FillConatcsGrid();
CheckSessionId();
}
}
GoodLuck
|
|
|
|
|
This will not work as user may start my application from different page
|
|
|
|
|
If your methods are Application specific, and wiil be same for all then users then you can call your methopds from the function Application_Start of Global.asax file.
and if it user specific then you can call your methopds from the function Session_Start of Global.asax file.
|
|
|
|
|
Tnx, it was exactly what I asked for. Thank you
|
|
|
|
|
your welcome
|
|
|
|
|
You can use methods of Global.asax file
see help of Global.asax file in google
|
|
|
|
|
The Global.asax file is the central point for ASP.NET applications. It provides numerous events to handle various application-wide tasks such as user authentication, application start up, and dealing with user sessions.The Global.asax file, which is derived from the HttpApplication class, maintains a pool of HttpApplication objects, and assigns them to applications as needed. The Global.asax file contains the following event:
Application_Start : Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
you can use this event it to perform the actions you wanted.
|
|
|
|
|
Hey guys, I would display a calender when a user hovers over my dropdowlist box.
Is this possible?
I tried to use the SelectedIndexChanged and TextChanged events to make the calender
visible but it won't work. And yes autopostback is set to true.
Any ideas??
Thanks,
Morg
|
|
|
|
|
Instead of trying code behind, try javascript for mouseover event.
|
|
|
|
|
Thanks man, do you know what java script code you can use for that,
am not good with javascript..tried google and no help there.
Please help if you can.
Thanks
Morg
|
|
|
|
|
Without the code, its not possible to give some relevent answer
|
|
|
|
|