|
I have two web apps each using the asp.NET 2.0 Membership providers set with the same application name and the same database so when someone registers an account on one site it is available on the other as well. However, I would like to configure it so that when a user logs in on one site and follows a link to the second he is automatically authenticated on the second site. Is this possible?
|
|
|
|
|
I have a datagrid with a checkbox in it, when the checkbox is checked it writes its ID to a hidden control (via javascript). There is multiple pages in this datagrid, and when I go to page two, then back to page one, my checkbox's are not checked and the hidden control is not populated either.
Anyone know a trick to keep the checkbox's selected as well as the hidden textbox populated with each checkbox's id?
This is VS2003 and VB.Net
Steve Welborn
Software Engineer
BitWise Solutions
|
|
|
|
|
On the page change event store the values from the hidden control to a static hashtable where the Key is the unique id for the row and the value is a bool as to whether the checkbox is checked. Then in the DataBound event (or whatever the DataGrid equivilant is called) check each row id against the hashtable, if it finds an entry check/uncheck the checkbox accordingly.
|
|
|
|
|
Not a bad idea. I will try that tonight then and see if that solves it.
Thanks for the reply.
Steve Welborn
Software Engineer
BitWise Solutions
|
|
|
|
|
I currently have a datagrid (yes, the ongoing datagrid saga). I have one main datagrid and three nested datagrids.
(I took out the ASP code as it didn't copy right.)
This is how I bind the data to the main grid:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
<br />
<br />
<br />
string SQLString = "SELECT p.PartNumber, p.ID as ptID, pt.description, dd.DrawingNumber, dd.DrawingRevision, dd.DwgPath FROM parts p INNER JOIN PartTypes pt on pt.ID =p.PartTypeID LEFT JOIN DraftingData dd on dd.PartID = p.ID WHERE p.PartNumber = @PartID;SELECT w.weight, wt.Description AS wtDescription, p.PartNumber from weights w INNER JOIN weighttypes wt on wt.ID = w.weighttypeid INNER JOIN Parts p on w.PartID = p.ID WHERE p.PartNumber = @PartID;SELECT c.cost, p.PartNumber, ct.Description AS ctDescription from Costs c INNER JOIN Parts p ON c.PartID = p.Id INNER JOIN CostTypes ct on ct.Id = c.CostTypeID WHERE p.PartNumber = @PartID; SELECT s.SubPartID, s.Quantity, s.Sequence, p.PartNumber FROM SubParts s INNER JOIN Parts p ON s.PartID = p.Id "; <br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", strPartNumberInputReference);<br />
SqlDataAdapter adapter = new SqlDataAdapter(cmd);<br />
adapter.Fill(ds);<br />
<br />
ds.Tables[0].TableName = "Rest";<br />
ds.Tables[1].TableName = "Weights";<br />
ds.Tables[2].TableName = "Costs";<br />
ds.Tables[3].TableName = "Subparts";<br />
<br />
<br />
dgParts.DataSource = ds;<br />
dgParts.DataBind();<br />
Session["ptNum"] = strPartNumberInputReference;<br />
<br />
}
I played around and could not get the nested datagrids to populate. I got them to populate with variants of this:
protected DataView getWeightInfo (string _PartNumber)<br />
{<br />
DataView _weight = ds.Tables["Weights"].DefaultView;<br />
_weight.RowFilter = "PartNumber='" + _PartNumber + "'";<br />
return _weight;<br />
}
So to add a new line to the main datagrid I use this:
private void add_Click(object sender, System.EventArgs e)<br />
{<br />
DataTable dt = ds.Tables["Rest"];<br />
DataRow row;<br />
row = dt.NewRow();<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
row["PartNumber"] = strPartNumberInputReference; <br />
row["DrawingNumber"]=DBNull.Value;<br />
row["DrawingRevision"]=DBNull.Value;<br />
row["DwgPath"]=DBNull.Value;<br />
dt.Rows.Add(row); <br />
dt.AcceptChanges(); <br />
dgParts.DataSource=dt; <br />
dgParts.DataBind();<br />
<br />
<br />
}
This works perfect. So I created a second button of "addWeight" and basically did the same thing:
private void addWeight_Click(object sender, System.EventArgs e)<br />
{<br />
DataTable dt = ds.Tables["Weight"];<br />
DataRow row;<br />
row = dt.NewRow();<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
row["weight"] = DBNull.Value;<br />
row["wtdescription"] = DBNull.Value;<br />
dt.Rows.Add(row); <br />
dt.AcceptChanges(); <br />
dgWeights.DataSource=dt; <br />
dgWeights.DataBind();<br />
}
TWO problems:
1. It does not add a line to the weights nested datagrid. How to fix this?
2. If I add a line to the main datagrid first, then click the weights one, the first added line disappears. How to make the blank line static?
THANKS AGAIN ALL and sorry for the long post!
-- modified at 16:39 Tuesday 27th June, 2006
|
|
|
|
|
Maybe there is just something wrong on my end but the text in your post is all over the place, like css positioning gone wild. Like I said may just be me, Firefox 1.5
|
|
|
|
|
Oh, I forgot that when I cut and paste my ASP it never looks right.
|
|
|
|
|
hi
i want to know that how can i implement a menu bar in an webpage without using javascript is there any other way or software tool through which i can implement it as i am not in touch with javascript.
|
|
|
|
|
|
You could buy third party controls from a company like Telerik or upgrade to .NET 2.0
|
|
|
|
|
I've read some previous posts but am a bit confused. (Imagine that...) I have a webpage in an asp.net application in which the user enters a part number in a textbox.
strPartNumberInputReference = txtPartNumberInput.Text;
What I want to do is make this a session variable so that other pages can access this number. Basically the second web page will load data based on that part number entered.
Where within the code do I do this? Do I just put it in the first page? Within which function? Can I just do Session ["ptNum"] = strPartNumberInputReference and use it in the other pages. (I assume not as this doesn't seem to be working.) If I do the session in a function, does it have to be a public function?
As always, big thanks.
|
|
|
|
|
You may need to check your IIS settings to make sure session variables are enabled. Also check for session pooling for sessions to persist throughout the webspace. I have to believe that it must be a global setting in IIS.
|
|
|
|
|
leckey wrote: If I do the session in a function, does it have to be a public function?
No, you can do it in any function you want, in any page you want.
When you retrieve your object from session, be sure to cast it, as it is returned back as object
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
-- modified at 9:04 Wednesday 28th June, 2006
|
|
|
|
|
Elina Blank wrote: be sure to cast it, as it is returned back as string
Could you give me an example of what you mean?
Thanks!
|
|
|
|
|
Sure.
Here you are:
MyObjectType myObj = (MyObjectType)Session[myObjSessionIndex]
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it! ![Blush | :O](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_redface.gif)
|
|
|
|
|
Okay, so something like this?
string strPartNum = (string)Session(what the heck would my index be? Don't I give it a name or something in parenthesis?)
Thanks again for your help!
|
|
|
|
|
your index is the name in of your variable.
Store object in session
Session[name] = object
Retrieve from session
object = Session[name].ToString()
name is any string variable
ex:
name= "myObjectSessionKey";
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it! ![Blush | :O](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_redface.gif)
|
|
|
|
|
Okay, I don't think I'm doing this right. In my first .aspx.cs page I declared:
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
Session["ptNum"] = strPartNumberInputReference;<br />
if (Page.IsPostBack)<br />
{<br />
<br />
BindData();<br />
}<br />
}
In the second aspx.cs page I did:
Session["test"] = object;<br />
object = Session["test"].ToString();
But the compiler doesn't like object just hanging out like that. What am I missing?
|
|
|
|
|
leckey wrote: Session["test"] = object;
object = Session["test"].ToString();
What type is your object?
try
object = (myObjectType)Session["test"];
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it! ![Blush | :O](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_redface.gif)
|
|
|
|
|
I placed the following in the second .aspx.cs page:
object = (string)Session["test"];
I get the error "identifier expected"
|
|
|
|
|
Can you send code snippet, please?
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it! ![Blush | :O](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_redface.gif)
|
|
|
|
|
No problem! Here is page one aspx.cs:
protected string strPartNumberInputReference;<br />
.<br />
.<br />
.<br />
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
Session["ptNum"] = strPartNumberInputReference;<br />
if (Page.IsPostBack)<br />
{<br />
<br />
BindData();<br />
}<br />
}
Page 2 code behind:
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
object = (string)Session["ptNum"];<br />
if (!Page.IsPostBack)<br />
{<br />
<br />
BindData2();<br />
test2 = txtTest.Text; <br />
}<br />
}
|
|
|
|
|
On which line the compiler complains?
Have you declared/initialized object variable?
But first check, that it is not a keyword?
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it! ![Blush | :O](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_redface.gif)
|
|
|
|
|
Now the session variable is giving me a different problem
Basically what I'm trying to do: On the first page user enters a partnumber and the datagrid populates based on that partnumber. User goes to second page, second page already recognizes part number and populates a new grid based on that partnumber.
The BindData function for the first page works fine:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
<br />
<br />
string SQLString = "SELECT w.weight, wt.Description AS wtDescription, p.PartNumber from weights w INNER JOIN weighttypes wt on wt.ID = w.weighttypeid INNER JOIN Parts p on w.PartID = p.ID WHERE p.PartNumber = @PartID"; <br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", strPartNumberInputReference);<br />
SqlDataAdapter adapter = new SqlDataAdapter(cmd);<br />
adapter.Fill(ds);<br />
<br />
dgParts.DataSource = ds;<br />
dgParts.DataBind();<br />
<br />
<br />
}
Page Load where session variable is:
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
Session["ptNum"] = strPartNumberInputReference;<br />
if (Page.IsPostBack)<br />
{<br />
<br />
BindData();<br />
}<br />
}
So on the second page I have:
public string test2;<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
test2 = (string)Session["ptNum"];<br />
if (!Page.IsPostBack)<br />
{<br />
<br />
BindData2();<br />
; <br />
}<br />
}<br />
<br />
private void BindData2()<br />
{ <br />
string SQLString = "SELECT w.weight, wt.Description AS wtDescription, p.PartNumber from weights w INNER JOIN weighttypes wt on wt.ID = w.weighttypeid INNER JOIN Parts p on w.PartID = p.ID WHERE p.PartNumber = @PartID";<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", test2);<br />
SqlDataAdapter adapter = new SqlDataAdapter(cmd);<br />
adapter.Fill(ds2); <br />
ds2.Tables[0].TableName = "Weights";<br />
dgWeights.DataSource = ds2;<br />
dgWeights.DataBind();<br />
<br />
}
But I'm getting the error:Prepared statement '(@PartID nvarchar(4000))SELECT w.weight, wt.Description AS wtDes' expects parameter @PartID, which was not supplied
I'm trying to pass the test2 as the parameter which should be the strInputNumberReference from page 1.
So I think I still have something incorrect.
Again, thank you SOOO much for helping me with this!
|
|
|
|
|
You are welcome.
Check with the debugger, where exactly you fall down.
Unfortunatelly, I have to do my staff now.
Can not figure out the problem straight.
Just one thing: shouldn't you specify command type? Text/SP
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it! ![Blush | :O](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_redface.gif)
|
|
|
|