ラベル retrieve の投稿を表示しています。 すべての投稿を表示
ラベル retrieve の投稿を表示しています。 すべての投稿を表示

2012年3月26日月曜日

retrieve info dynamically created textbox in update panel

I have a textbox that is created in code in an Ajax Update Panel when then the user clicks on a dropdownlist.

I would then like to retreive the text that user types in:

Dim strTitleAsString =CType(Me.FindControl("txtPrimaryPersonTitle" + intSuggestedPrimaryPersonCount.ToString), TextBox).Text

It gives me an error that it can't find the control.

Can you offer any help??

Have you made sure that the textbox is re-created on postback?

You may also consider creating the textbox statically (in markup) instead of dynamically.
Set Visible=False in the markup, and make it visible in your dropdownlist code.
This prevents most of the problems inherent to dynamic controls.

Jos


hello.

how about a demo page so that we can see what you're doing? it has to be simple enough so that we ca simply copy/paste it in order to test it


Hi,

it can't find the control?

If the contorl still exist, the Id must not write.

I think it is easy to debug to see if the contorl is exist or not, and it is easy to find out what is the correct id of the contorl.

If you still have question,post up a repro of your issue.

Best Regards,

Retrieve JSON result set

What is the best method for retrieving a result set and returning a JSON object? I tried using a DataSet, but received a serialization error.

TIA

You do not have to do anything special to convert in JSON. The Asp.net Ajax Automatically handles it. But in case you want to some manual proessing use the JavaScriptSerializer.


You do not have to do anything special to convert in JSON. The Asp.net Ajax Automatically handles it. But in case you want to some manual proessing use the JavaScriptSerializer. The DataSet is not supported with the Current Version, Add the January CTP to work with DataSet and DataTable.


I am a little confused. Can you provide an example of how to retrieve a JSON serialized result set? Where do I find the January CTP?

TIA


You can find the January CTP from this linkhttp://www.microsoft.com/downloads/details.aspx?familyid=4CB52EA3-9548-4064-8137-09B96AF97617&displaylang=en

Retrieve value from a dynamically created control inside an UpadetPanel

I would like to dynamically create some controls - tablecells, textboxes, and dropdownlists inside an AJAX UpdatePanel.
How would I retrieve the values that user enters into these controls in my vb.net code behind?
Can you please provide vb.net sample code ??

Here is my code:

'creates the textboxes - works fine

For i = 1 To intUnseatedGuestCount
Dim txtFirstName As New TextBox
txtFirstName.ID = "txtFirstName" + i.ToString
Me.tdNewSeatingCards.Controls.Add(txtFirstName)
Next

'code to retreive the values - produces an error message

Object reference not set to an instance of an object

For i = 1 To Me.hidNewSeatingCardCount.value
strTXTName = "txtFirstName" + i.ToString
Dim myTXT As TextBox = CType(Me.tdNewSeatingCards.FindControl("txtFirstName" + i.ToString), TextBox)
strTest += myTXT.Text + "<br>"
Next

Thank you for your help

You are creating controls dynamically, So on every postback (even in asynchronous postbacks ) you have to create it


OK Here is my code to recreate the controls:

For i = 1 To Me.hidNewSeatingCardCount.Value
Dim txtFirstName As TextBox = CType(Me.tdNewSeatingCards.FindControl("txtFirstName" + i.ToString), TextBox)
txtFirstName.ID = "txtFirstName" + i.ToString
Me.tdNewSeatingCards.Controls.Add(txtFirstName)
strTest += CType(Me.tdNewSeatingCards.FindControl("txtFirstName" + i.ToString), TextBox).Text
Next

There are no error messages, but I am not getting the values that the user enters into the textbox.

Thank you


Hi,

Thank you for your post!

You should place your recreate code in the init event.

The cause of the issue is viewstate process is finished before you recreate your controls!

If you have further questions,let me know!

Best Regards,

retrieve value from a dynamically created control

I would like dynamically create some controls - tablecells, textboxes, and dropdownlists inside an AJAX UpdatePanel.

How would I retrieve the values that user enters into these controls in my vb.net code behind?

Can you please provide vb.net sample code ??

Thank you for your help

http://forums.devx.com/showthread.php?t=16770

http://mail.123aspx.com/ArticleFrame.aspx?res=31558


here is a nice tutorial with example / code on how to create Dynamic controls and how to retrieve values from these dynamic controls.. [Page_Init() event is used here...]

SingingEels : Dynamically Created Controls in ASP.NET

hope it helps./.

Retrieve viewstate during a GET request

I have a page with controls that specify a filter on a set ofresults. I have used ajax and the update panel to show updated resultsthrough asynchronous request when the filter gets updated. When theuser selects an item in the set they navigate to a different page...when they then hit the back button they return to the filter page butall the controls are all re-initialized.

What I've been trying isgenerating an id for the page on the initial request (as is done andnormally placed in a hidden field for my custom PageStatePersister thatkeeps the viewstate in a database) but then redirecting the user to aurl with the id appended. So when you later hit the back button youhave the id in the URL.


Next LoadViewState is NOT calledunless the request is the result of a postback. Well I've been tryingto initialize the ViewState in the Page_Load by callingLoadPageStateFromPersistenceMedium() and that does result in callingthrough my custom PageStatePersister... But the ViewState dictionary ofthe page does not get updated... what am I missing?

Or is there another way to accomplish not losing the filter values?

Ok...this is going to be hard for me to explain..but I shall try. And i will suggest two solutions. First of all remember client side styles are not persisted unless asked, and viewstate track changes to state only when tracking is enabled. So all your controls are reinitialised because tracking gets enabled after oninit() and then viewstate just deserializes the stored data.

So unless you set trackviewState(), viewstate is not tracking anything. (Once on, cannot be turned off) Once tracking is on..viewstates items can be marked dirty(IsItemdirty()). You can also set an item to be dirty. Basically tracking allows viewstate to monitor which of its elements have changed since TrackViewState() has been called. Statebag ignores the items that are not marked dirty when it comes to saving view state SaveViewState() and hence items not marked dirty are not serialized.

So one of the solution is to markitems dirty which you want to be persisted before that postback. The other is dont do it by ajax but by actual user controls.

Just a question for you to ponder, if you have two identical pages with a textbox and a button with on onclicking code.

as <as:textbox runat="server" text="abc"><asp:button runat="server" text="submit">

with other pages only having change in its text property as text="the quick brown fox jumps over the little lazy dog" Do the two pages have same viewstate?

Read this article if you want to understand viewstate.

http://msdn2.microsoft.com/en-us/library/ms972976.aspx


I appreciate your feedback but I'm not sure how it applies... I'm not having problems writing viewstate... I'm having problems loading the viewstate during a GET request. I'll try articulating my problem differently:

1) I've persisted the viewstate on the server side.
2) The viewstate is identified by a hidden field and so is in the form data during a postback (this already works)
3) On the first GET of a page I generate the identifier and redirect the request to a page with the viewstate identifier appended to the URL
4) By default Viewstate is NOT loaded during a GET request only POSTBACK
5) On the first GET of the URL+ViewstateID, the viewstate does not exist and the page runs through normal initialization
6) On subsequent requests to URL+ViewstateID does exist and I want to load this Viewstate from storage (see 4)
7) I've tried Page.LoadPageStateFromPersistenceMedium() which does call my pagestatepersister and retrieves the viewstate... now how do I apply this to the page instance...? can I ...?


before you move on to the next page, you can either save your viewstate as I said in my previous post and write it to a session and later on retreive the session, and put it back in viewstate.

Although this can be accomplished by plain sessions.