|
hi,
any one help me,
How to pass values from textboxes on one page to a "another page" using session.
I have the follwing code but it shows an error msg.
public string PassingSession ;
Session["strPharmacyId"] = txtPharmacyId.Text.Trim();
Session["strStoreName"] = txtStoreName.Text.Trim();
Session["strAddress1"] = txtAddress.Text.Trim();
Session["strCity"] = txtCity.Text.Trim();
Session["strState"] = txtState.Text.Trim();
PassingSession = PassingSession + Session["strPharmacyId"];
PassingSession = PassingSession + Session["strStoreName"];
PassingSession = PassingSession + Session["strAddress1"];
PassingSession = PassingSession + Session["strCity"];
PassingSession = PassingSession + Session["strState"];
Session["Pharmacy"] = PassingSession;
dtSession = (DataTable)Session["Pharmacy"];
msg: "can't convert string to datatable";
|
|
|
|
|
Vijay.RG wrote: dtSession = (DataTable)Session["Pharmacy"];
What you are doing over here?
|
|
|
|
|
Passing the session value to datatable object.
DataTable dtSession=new DataTable();
dtSession ==> Datatable object.
|
|
|
|
|
I think you have already got the answer from Manas Post.
Vijay.RG wrote: Passing the session value to datatable object.
Never do like that. It will cause very performance issue.
|
|
|
|
|
Vijay.RG wrote: PassingSession = PassingSession + Session["strPharmacyId"];
PassingSession = PassingSession + Session["strStoreName"];
PassingSession = PassingSession + Session["strAddress1"];
PassingSession = PassingSession + Session["strCity"];
PassingSession = PassingSession + Session["strState"];
Session["Pharmacy"] = PassingSession;
dtSession = (DataTable)Session["Pharmacy"];
You do not this piece of code at all.
You already have assigned the textbox values to the Session Objects, the only thing you need to do is to read it back in the next page.
In between, your design looks screwed and you should rather reconsider thinking of design before starting coding.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I got the code Mr.Manas Bhardwaj ...
Thanks.
|
|
|
|
|
Dont ever store Datatable in Session. It means a huge amount of data will be stored in Session, and for each user who browses the site.
So it will eat up all the app pool memory.
|
|
|
|
|
How can you convert a string to datatable because PassingSession is a string as you declared?
Here you are assigning values to session
Vijay.RG wrote: Session["strPharmacyId"] = txtPharmacyId.Text.Trim();
Session["strStoreName"] = txtStoreName.Text.Trim();
Session["strAddress1"] = txtAddress.Text.Trim();
Session["strCity"] = txtCity.Text.Trim();
Session["strState"] = txtState.Text.Trim();
No need of below code
Vijay.RG wrote: Session["strState"] = txtState.Text.Trim();
PassingSession = PassingSession + Session["strPharmacyId"];
PassingSession = PassingSession + Session["strStoreName"];
PassingSession = PassingSession + Session["strAddress1"];
PassingSession = PassingSession + Session["strCity"];
PassingSession = PassingSession + Session["strState"];
Session["Pharmacy"] = PassingSession;
dtSession = (DataTable)Session["Pharmacy"];
You have already filled the textbox value in session.Now it will be accessible throughout ther application.
Cheers!!
Brij
|
|
|
|
|
Hello,
I am doing my thesis on Windows Azure and I d like someone to show me how to store data in Windows Azure Tables and then how to publish on Azure Services Development Portal.
I would be glad if someone could send me a working example to take some ideas.
Some examples from msdn that I 've downloaded don't run on my computer and I don't know what is wrong.
Any help would be appreciated...
|
|
|
|
|
hi,
in my project we are using asp.net 2.0 GridView in so many places. Through out the project we are using GridView derived control.
public class GridView : System.Web.UI.WebControls.GridView
{
}
i have added code to maintain seleced checkboxes state, DataKey value ID of selected rows if user selects multiple rows from multiple pages navigation. i am storing the 1) ID, 2) Selected in the ViewState in the form of List.
For this i have 2 methods
StoreCurrentViewState()
RestorePastViewState
this code i have used at...
protected override void OnPageIndexChanging(GridViewPageEventArgs e)
{
StoreCurrentViewState();
base.OnPageIndexChanging(e);
RestorePastViewState();
}
also added at
protected override void OnDataBinding(EventArgs e)
{
StoreCurrentViewState();
base.OnDataBinding(e);
}
protected override void OnDataBound(EventArgs e)
{
base.OnDataBound(e);
RestorePastViewState();
}
it is maintaining selected checkboxes states during the gridview page naigation.
my query is ...
in one aspx page i have 4 grids and for all page it is storing in single ViewState object. i wanted to store these values in sepearate viewstate for each gridview && i need to reset the ViewState object if gridview loads first time. How can i do?
please provide ur inputs...
Ramana
|
|
|
|
|
Use ID or UniqueID of GridViews as the key when storing to ViewState. As each ID is going to be unique in a page, they will be maintained separately for each GriView in ViewState object.
|
|
|
|
|
store the viewstate as GridviewID$ID
and then split it on restoring.
|
|
|
|
|
hi
i am using Application Object to count the number of users created for a webpage.I am using following code in C#:
1. protected void Session_Start(object sender, EventArgs e)
2. {
3. int userCount=(int)(Application["userCount"]) ;
4. Application["userCount"] = ++userCount;
5. }
It gives error @ line 3 saying Object reference not set to an instance of an object. in WebPage.
how do i increment Application Object Value in Session_Start?
i tried
Application["userCount"] + =1 but it says Can't convert Int to Object type....
I am using VS 2008 /ASP.NET 3.5
thanx in advance..
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
Does your Application["userCount"] item exist the first time this code has run? Your code doesn't handle the possibility of it not being there.
|
|
|
|
|
i thought Application object is global object and therefore it exists/initialized by default.....thanx for help..i'll check on the web
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
As indeed it is. However your item in the Application may not have been added, so it will not exist.
|
|
|
|
|
QuickDeveloper wrote: 1. protected void Session_Start(object sender, EventArgs e)
2. {
3. int userCount=(int)(Application["userCount"]) ;
4. Application["userCount"] = ++userCount;
5. }
It is always better to use Application.Lock() and Application.Unlock() before any kind of operation with Application Variable. Because ASP.NET is multithreaded and when multiple users accessing the web site at the same it is required to synchronized the data
void Session_Start(object sender, EventArgs e)
{
if (Application["userCount"] != null) {
Application.Lock();
int visitorCount = (int)Application["userCount"];
Application["userCount"] = userCount++;
Application.UnLock();
}
}
|
|
|
|
|
Check before you call Application object placed in the variable:
if (Application.AllKeys.Contains<string>("userCount"))
{
Application.Lock();
int item = Convert.ToInt32(Application["userCount"]);
Application["userCount"] = item + 1;
Application.UnLock();
}
else
{
Application.Set("userCount", 1);
}
|
|
|
|
|
Abhishek Sur wrote: if (Application.AllKeys.Contains("userCount"))
thanx Abhishek..it really works!!!
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
Hi,
I am using the following code in my Web application for checking whether the image at the remote server exist or not. This works perfectly on my local machine, but when I upload this code on my Live website, it returns no response( response = null)
private static bool IsImageExists(string imageURL)
{
bool fileExist;
HttpWebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imageURL);
request.Method = "HEAD";
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
using (response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.OK)
{
// If no exception was thrown until now, the file exists and we are allowed to read it.
fileExist = true;
}
else
{
// Some other HTTP response - probably not good.
// Check its StatusCode and handle it.
fileExist = false;
}
}
}
catch
{
fileExist = false;
}
return fileExist;
}
Is this threading related issue. Please give me quick solution.
Thanks in Advance.
d'kng
|
|
|
|
|
Not getting any error? Looks like your server may be using proxy. Try setting the proxy details to the request object.
|
|
|
|
|
Thanks Navneet,
I am updating the code with this additional lines to set proxy.
WebProxy browserProxy = new WebProxy();
// Obtain the Proxy Prperty of the Default browser.
browserProxy = (WebProxy)request.Proxy;
request.Proxy = browserProxy;
I'll update you once it is done.
D'kng
|
|
|
|
|
Hey Guys need help
I created a DataSet with the query that i need. However i will like to display the DataSet Detail to the crystal Report
DataSet ds = DBCall.ReturnDataSet(SQL , DBCall.ITSDatabase);
CrystalReportViewer1.DisplayGroupTree = false;
CrystalReportViewer1.HasCrystalLogo = false;
ReportDocument myReportDocument;
myReportDocument = new ReportDocument();
myReportDocument.Load(Server.MapPath("CrystalReport2.rpt"));
myReportDocument.SetDataSource(ds);
CrystalReportViewer1.ReportSource = myReportDocument;
CrystalReportViewer1.DataBind();
However i can't seem to display it one the report. I know this is the Push Method however
I need to set the layout of the report right? How am i suppose to set it ?
Many thanks
KaKaShi HaTaKe
|
|
|
|
|
Hi
I'm trying to play audio on my webpage directly from the databse, can anyone help me with the code for my method: playAudio(byte[] stream), please see my code bellow.
thanks n advance
<pre>string sql = @"Select AudioFile from tbDeviceResults where DialResultID = @ID";<br />
SqlConnection oCon = new SqlConnection(DatabaseConnection.ConnectionString);<br />
SqlCommand cmd = new SqlCommand(sql, oCon);<br />
cmd.CommandType = CommandType.Text;<br />
cmd.Parameters.AddWithValue("@ID", ID);<br />
DataTable tblData = new DataTable();<br />
try<br />
{<br />
new SqlDataAdapter(cmd).Fill(tblData);<br />
foreach (DataRow row in tblData.Rows)<br />
{<br />
stream = (byte[])row["AudioFile"];<br />
playAudio(stream);<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
<br />
<br />
}<br />
void playAudio(byte[] stream)<br />
{<br />
<br />
}<br />
<br />
</pre>
|
|
|
|
|
DotNetCoderJunior wrote: can anyone help me with the code for my method: playAudio(byte[] stream),
You will need to make an ASP.NET page which reads the content as you arealy did and set the appropriate MIME type using ContentType
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|