Marc Jennings
Guest
|
Posted:
Fri Jan 28, 2005 8:09 pm Post subject:
Getting lost in the logic flow.... |
|
|
Hi,
I am having a bit of trouble getting my head around the flow of logic
in a web part I am writing.
Here is the scenario...
TextBox and button allow the user to search in a database for a
specific string.
On clicking on the button, a query is run to return the number of
records. If it is 0, a message is displayed to that effect. If there
is one record, another query is run to return the data, and that data
is then displayed.
My problem is in the 3rd scenario, more than one result. The code to
handle this creates a dataset and populates it from sql with all the
possible results. It will then display the first result's data (in
the same format as the single result code). The full result set is
also shown in a datagrid to allow the user to select another item to
display. (With me so far?)
The datagrid has an EditCommandColumn with a Test value of "Show", and
is wired into an event that (should, for the moment) spits out to the
browser the index of the selected item ready to be worked with.
However, it does not appear that this event is being fired. I suspect
that viewstate and the conditional nature of creation of the
underlying dataset are to blame, but I can't seem to find a
workaround.
If anyone would like to ask me for further info so they can help me
out, I am more than happy to supply details,( it's just really hard to
figure out how much detail to gfo into in an initial post!!)
TIA
Marc. |
|
Wei-Dong XU [MSFT]
Guest
|
Posted:
Sat Jan 29, 2005 6:48 am Post subject:
RE: Getting lost in the logic flow.... |
|
|
Hi Marc,
From my understanding, you found the click event of the show link of the
EditCommandColumn hadn't be sent to the server at the web part. If I lose
target, please correct me with more detailed information.
As I know, at your scenario, the server control is created at the runtime.
This is what we call dynamic control, so the viewstate of this control may
not be preserved when the webpart is submitted. You must create your
dynamic controls very early in the Webpart's lifecycle such as during Init
or Load.
From the SDK article "OnInit(System.EventArgs) Method" of Web Part class,
you can add one eventhandler to the Init event (same to Load ) and then
create the datagrid at that event handler.
this.Init += new EventHandler (MyInitHandler);
Another way, you can also create one override method for OnInit and OnLoad
of the WebPart class. For more information, this kb article introduces how
to create one dynamic control at ASP.net.
HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/kb/317794/
Please feel free to let me know if you have any question.
Best Regards,
Wei-Dong XU
Microsoft Product Support Services
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/technicalsupport/supportoverview/40010469
Others: https://partner.microsoft.com/US/technicalsupport/supportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/default.aspx?scid=%2finternational.aspx.
=====================================================
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights. |
|