Showing posts with label based. Show all posts
Showing posts with label based. Show all posts

Saturday, March 31, 2012

Table Web Control

I'm using a Table web control to dynamically create checkboxes, and check/uncheck/enable/disable them based on values returned from different datasources. In this case, I'm using several DataTables.

I've completed the table on load, and all of the checkbox controls load up as expected, however I now need to submit any changes based on the users values. I've been googling for a good article on the Table web control but haven't found anything that will help. Does anyone know of any articles, or have sample code for maintaining state of these controls and iterating through them so I can create my dynamic SQL based on selections?

Thanks.From the SDK:

"Note: Programmatic additions or modifications to a table row or cell will not persist across posts to the server. Table rows and cells are controls of their own, not properties of the Table control. Changes to table rows or cells must be reconstructed after each post to the server."

Ok, so I think that answers my viewstate problem. I DO recreate this table on page load everytime, so I don't think I need to worry about that.

Any help on muddling through the selected checkboxes of a dynamically created table web control, would still be very beneficial to my cause.
Ugh, I'm fried here...

The viewstate will STILL be a problem, because I wasn't thinking that with each postback, my table would just be re-created, therefore I won't get the modified values on submission.

I keep talking to myself but oh well...

Just to reiterate, I need help on maintaing state for a dynamically created table web control, and how to iterate through the controls that were created in that table on postback.
Dear Forum,

Hi! It's me again!

Ok, so after a little more research I found that people are suggesting the Request.Form() to collect information about the controls. Does that sound right? I guess if you can't take advantage of viewstate in this situation, then Request.Form() is the way to go.

Taking that into consideration, I don't think I can really "iterate" through the controls in my dynamic table, but maybe create some variables that will hold the number of checkbox controls say, when I create the table. So maybe it would look something like this:

pseudocode -
' Creating the table
Dim cb as CheckBox
Dim cbCounter as Int32
'Dynamically create checkbox here and increment the checkbox counter

Then later when I retireve the values within my table...

'Go through each of the checkboxes and determine the value
for x=0 to cbCounter.Length - 1
'check the value of checkbox "x" here

Does this sound like a logical resolution? Am I taking this too far and there is an easier path that I'm missing here? Does anyone really care at this point? :)
Hi FrankWhite,

I'm having the same problem here. I'm fetching values from a MySQL database, I show them in a nice table with checkboxes. But when the user clicks "submit" my checkboxes are lost (since my table won't keep them).
So I'm looking for the same solution: how can I keep all generated checkboxes, so I can check which of them are checked by the user?

If someone has experience with this scenario and knows how it can be done, please post it here for me and FrankWhite ;)

Thanks in advance!
1. Try to stay away from dynamically creating controls that need to keep their values during postbacks.

2. Modify the way you search for information. More than 50% of programming involves just trying to find out how to do stuff. Your problem is not with viewstate, but with the ASP.NET lifecycle.

To answer both your question, you will need some patients.This article will answer your questions, but you have to read every word carefully. DONT skip to the end and read the conclusion as you will miss out on important things that you should learn.

Jagdip
(Haven't read the article yet)

I did come to a solution the other day. Basically on Page_Load my table is recreated everytime. When the submit button is pressed, I simply do Request.Form() on the checkbox controls. I don't have the code in front of me at the moment, but I basically did the following to solve my problem.

1.) Created a variable that would serve as a counter for my checkboxes.
2.) When the checkbox was created, I would give it the id: "chk_" & chkCtrls (variable that was the counter)
3.) In the btn_submit() I created a loop to iterate through each of the checkbox controls (well not really the controls, rather the # of controls). In the loop I would check if the checkbox was checked and do something according to that:

for x = 0 to chkCtrls
if Request.Form("chk_" & x) = "On" Then
'do something
end if
next

There was a lot more to it then this for my situation, but I think this will give you a good idea. Let me know if this helps, or if you figured out a different solution. In the meantime, I'll need to peep this article...
I used the same solution, I recreated my checkbox collection each time in Page_load, and used Request.Form to check wether the "check all" was checked or unchecked to set a default checked value on each checkbox (true/false). Then on the submit button I used Request.Form again to check the status of each generated checkbox by checking for controls like "chk" + intID.
This does the trick I needed very well.

I'll take a look at the article as well, in case this is not the right way of programming this :)

Thanks for the help,
Speerman
Alright, alright, I'll give you the jist of it. I'm not an expert in this (just been reading around a lot) so here goes.
Basically, the ASP.NET life cylce loads your info like this:

Page_Init
Load ViewState
Page_Load
Run any controls functions (e.g. button_click functions, etc.)

From this you can see that if you create controls dynamically, then they will be displayed on the page; but their viewstate will not be 'loaded'. What we need is a way to create the controls before the Load Viewstate state.

Solution: If you are using VS, the you know there is a region called " Web Form Designer Generated Code ". In this you will find:


'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

All you need to do is call the function that creates the dynamic controls from within the Page_Init function. That's it (i think - havent got a chance to try it).

But please, read the article. You will have a better understanding of ASP.NET which means better pages (and maybe a pay rise - you can tell why I read the aticles ;-)

HTH
Jagdip

Saturday, March 24, 2012

Tag A Photo

I have a page that loads a photo based on a query string in the URL.

I am attempting to allow the uploader of the image to "tag" people in the photo. A tag will be a javascript positioned "frame" over the top of the image, the frame will only appear when the user hovers their mouse over a name of someone in that photo.

I have sorted tagging as in, the user can set people in a photo. Does anyone know any java script that will allow me to :

1) Limit the users tagging abilitys to only the photos area : "image1".

2) Will save the location (from top and left) of the frame.

I hope this makes sense. If you wish to see an example "facebook.com" already does this type of tagging. I am a bit of a newbie when it comes to javasctript so i dont really know where to start with this. If there is a way of doing this that is better than the way i am trying please let me know. thanks si!

Hi,

Take a look here

http://weblogs.asp.net/scottgu/archive/2006/07/19/Building-a-Photo-Tagging-Application-using-ASP.NET-2.0_2C00_-LINQ_2C00_-and-Atlas.aspx


thats perfect except i didnt want to use class diagrams if possible. I will give it a go and see if it works for my project. Thanks a million! si!


i feel i should explain slightly more. I want the user to be able to click "photos containing you" button and it`ll load a page which`ll filter out all images that do not have a tag of them. I was going to do this from a querystring which seems simple enough to do, but its the cloud control and storing the tags that is causing me issues. Si!

TagPrefix and Assemblies

I'm trying to get something to work based on an existing application. In the existing web.config, there's are assemblies like this one:

<addassembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>

Can I copy and paste these assemblies into my web.config or were these generated some way that I need to generate them.

Also, in the master page, there's this tag prefix:

<%@dotnet.itags.org.RegisterTagprefix="SharePoint"Namespace="Microsoft.SharePoint.WebControls"Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Can I just copy and paste this into mine, or do I have to create a unique one...and how would I do that?

Thanks!

Yupp! Go ahead use them. They'll work.


Unless an assembly is of different build/version, you can simply copy && paste.

Tuesday, March 13, 2012

td bgcolor based on variable

Hello, I am fairly new at ASP.Net and I am using 2.0. I am populating a table from a SQL query. If the field is blank/null, I would like to color the background yellow in the. How do I test for the variable and make this happen? Thanks for your help. Jim

This should help

Custom Formatting Based Upon Data

http://www.asp.net/learn/dataaccess/tutorial11vb.aspx?tabid=63


Create a databound envent handler and make the corresponding format according to the data you get. Yeah, the above link a great one and should solve your problem. take a deep look at it. thanks