Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Wednesday, March 28, 2012

The command MoveNext is not valid for the previous step, how to prevent this?

I am using WizardControl, on the first page, I have a validator, when user click next button or press enter, the validator will check the data and decide which step is the next step. But if I let it move to the last page, I will get error "The command 'MoveNext' is not valid for the previous step,...",I think it is because the last step doesn't have movenext button, and the validate event happens before nextbutton event, after it moves to the last step by code in the validator event, the nextbutton event need to be attached, but it could not find the object to attach. So I think I need a way to cancel the nextbutton event, any suggestion?

thanks!I am not sure what do you mean by "validator will check the data and decide which step is the next step." Can you post your code?
To cancel the nextbutton event you can do something like

protectedvoid Wizard1_NextButtonClick(object sender,WizardNavigationEventArgs e){
if(Wizard1.WizardSteps[e.CurrentStepIndex].StepType ==WizardStepType.Finish)
e.Cancel =true;
}


Thanks for reply.

On my first step page, there is a TextBox, user will type in their areacode, so I put a validator there to make sure user type in an areacode, and check if the areacode is valid, if it is valid, it will control which step is the next according the areacode. It looks like if I should put the code to decide which step to go into the NextButtonClick handler, but the validator event raises before the NextButtonClick event.
I saw that NextButtonClick event gets fired and saw the exception.
Canceling inside the event handler would not work in this scenario. So to avoid the firing of next button event completely wizardStep need to be templated. So you can get more control over the behavior of nextButton in the start step. Here is one example where next button click event doesnt get fired as the nextButton the the StartNavigationTemplate doesnt have the Command defined. I think that will server your purpose.

<asp:WizardID="Wizard1"runat="server">
<WizardSteps>
<asp:WizardSteprunat="server"Title="Step 1">
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:CustomValidatorID="CustomValidator1"runat="server"ErrorMessage="CustomValidator"OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</asp:WizardStep>
<asp:WizardSteprunat="server"Title="Step 2">
</asp:WizardStep>
<asp:WizardStepID="Step3"runat="server">
</asp:WizardStep>
</WizardSteps>
<StartNavigationTemplate>
<asp:ButtonID="StartNextButton"runat="server"Text="Next"/>
</StartNavigationTemplate>
</asp:Wizard>

HTH,
Vishal

Monday, March 26, 2012

The ConnectionString property has not been initialized

hi

i'm using the register.aspx just to enter data, and i'm not using the code for cookies so my code when preesing register button (note i'm using instead of customer , auther)

Sub Button1_Click(sender As Object, e As EventArgs)

' Only attempt a login if all form fields on the page are valid

If Page.IsValid = True Then

' Add New Customer to CustomerDB database
Dim accountSystem As ASPNET.StarterKit.Commerce.AutherregisterDB = New ASPNET.StarterKit.Commerce.AutherregisterDB()

Dim Autherid_table as String = accountSystem.AddAuther(Name.Text, Email.Text, Password.Text)

End If

End Sub
and i'm using same classess and declare connection string in webconfig localhost

but i'm getting the error message after filling the register form textboxes

The ConnectionString property has not been initialized.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.InvalidOperationException: The ConnectionString property has not been initialized.
Source Error:

Line 15: Line 16:Line 17: Dim Autherid_table as String = accountSystem.AddAuther(Name.Text, Email.Text, Password.Text)Line 18: Line 19:

Source File:E:\AbdCommerce\Autherregfrm.aspx Line:17
Stack Trace:
[InvalidOperationException: The ConnectionString property has not been initialized.] System.Data.SqlClient.SqlConnection.Open() +432 ASPNET.StarterKit.Commerce.AutherregisterDB.AddAuther(String fullName, String email, String password) +380 ASP.Autherregfrm_aspx.Button1_Click(Object sender, EventArgs e) in E:\AbdCommerce\Autherregfrm.aspx:17 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1277
is there any idea for the cause??

thanks

When you use web config to store setting strings, you need to import namespace System.Configuration. Why did you see the error on the codeDim Autherid_table as String = accountSystem.AddAuther(Name.Text, Email.Text, Password.Text)?Because the code call a classs that does function to add auther. So, try to go to the class file to add System.Configuration namespace.

The damn Enter button and ASP.NET

If you have a Datagrid with the functionality to edit and update rows and
then also a Save, Add new and Back buttons at the bottom of the page. The
Enter button is all messed up... add to this a bunch of TextBox fileds with
Multiline support in the Edit mode...
So if I enter the Edit mode of a row and put focus in the multiline textbox
and press enter I of course want to create a line feed in the text box.. but
no.. it triggers any button the page feel like at that time... when you tab
around in the Input fields you see the blu little line jump around on
buttons (that indicated the Defautl Enter button)... Sometimes it's the save
button that triggers and sometimes in the back button or sometimes even the
deletecommand of the other rows that are not in the EditMode.
So, yeah sure I could, which I have on other pages, disabled the Enter and
Return buttons thru Javascript onkeypress but on this page I really need to
have the line feed thingy working in the Multiline boxes.. please help.
best regards
/Lars NetzelHi Lars
I've had the problem with ASP pages submitting the first button on the page
or not the button i intented it to submit.
The way i got around this, was by creating a <input type=button runat=server
id=tb />, setting the OnClick to point to my required method through the
code behind, then attaching a JavaScript on enter to all the textboxes i
want to submit this with. (the opposite to you disabling the enter button)
An annoying work around, but a work around.
I have never had the problem when hitting enter on a multiline textbox, it
submits the form.
However, attaching a Javascript onclick like i said above would do this.
So, are you sure there no javascript actions on you textbox that could cause
it to submit on enter rather than create a new line feed.
Double check this through IE by viewing source and checking there is no
OnClick event.
HTH (I know it may be no solution, by no one else has answered your plea for
help yet :))
"Lars Netzel" <uihsdf@dotnet.itags.org.adf.se> wrote in message
news:OGu697XoFHA.3316@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> If you have a Datagrid with the functionality to edit and update rows and
> then also a Save, Add new and Back buttons at the bottom of the page. The
> Enter button is all messed up... add to this a bunch of TextBox fileds
> with Multiline support in the Edit mode...
> So if I enter the Edit mode of a row and put focus in the multiline
> textbox and press enter I of course want to create a line feed in the text
> box.. but no.. it triggers any button the page feel like at that time...
> when you tab around in the Input fields you see the blu little line jump
> around on buttons (that indicated the Defautl Enter button)... Sometimes
> it's the save button that triggers and sometimes in the back button or
> sometimes even the deletecommand of the other rows that are not in the
> EditMode.
> So, yeah sure I could, which I have on other pages, disabled the Enter and
> Return buttons thru Javascript onkeypress but on this page I really need
> to have the line feed thingy working in the Multiline boxes.. please help.
> best regards
> /Lars Netzel
>
Thank you! I had some thoughts about the way you suggested but it seemed
like such an ugly workaround that I didn't really think that anyone would do
it but after looking around so more it seems like this is a quite common way
of fixing things, using the onfocus and onblur events to alter behaviors on
page.
So I did this:
I catch onkeypress on the body element and have a condition for the Enter
button to return true or false... then on the onfocus and onblur events of
the textboxes, I change a variable weather to use the condition for the
enter check or not. Work pretty darn good:)
Thanks for the thoughts.
And by the way.. the textboxes where not set to MultiLine... hmmm.. I wonder
why there was no LineFeed...
Take care
/Lars
"Grant Merwitz" <grant@dotnet.itags.org.workshare.com> wrote in message
news:eEV7z1ZoFHA.3608@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
> Hi Lars
> I've had the problem with ASP pages submitting the first button on the
> page or not the button i intented it to submit.
> The way i got around this, was by creating a <input type=button
> runat=server id=tb />, setting the OnClick to point to my required method
> through the code behind, then attaching a JavaScript on enter to all the
> textboxes i want to submit this with. (the opposite to you disabling the
> enter button)
> An annoying work around, but a work around.
> I have never had the problem when hitting enter on a multiline textbox, it
> submits the form.
> However, attaching a Javascript onclick like i said above would do this.
> So, are you sure there no javascript actions on you textbox that could
> cause it to submit on enter rather than create a new line feed.
> Double check this through IE by viewing source and checking there is no
> OnClick event.
> HTH (I know it may be no solution, by no one else has answered your plea
> for help yet :))
>
> "Lars Netzel" <uihsdf@dotnet.itags.org.adf.se> wrote in message
> news:OGu697XoFHA.3316@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
>
HAHA, thats is quite funny
glad you came right
"Lars Netzel" <uihsdf@dotnet.itags.org.adf.se> wrote in message
news:u7Dn3sioFHA.468@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
> Thank you! I had some thoughts about the way you suggested but it seemed
> like such an ugly workaround that I didn't really think that anyone would
> do it but after looking around so more it seems like this is a quite
> common way of fixing things, using the onfocus and onblur events to alter
> behaviors on page.
> So I did this:
> I catch onkeypress on the body element and have a condition for the Enter
> button to return true or false... then on the onfocus and onblur events of
> the textboxes, I change a variable weather to use the condition for the
> enter check or not. Work pretty darn good:)
> Thanks for the thoughts.
> And by the way.. the textboxes where not set to MultiLine... hmmm.. I
> wonder why there was no LineFeed...
> Take care
> /Lars
>
> "Grant Merwitz" <grant@dotnet.itags.org.workshare.com> wrote in message
> news:eEV7z1ZoFHA.3608@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
>

Saturday, March 24, 2012

The difference between Postback and CallBack ?

I know that Postback referring to the action users click a button to submit the form data.

In what situations do we say mention thecallbackaction?

(I found that there is a property Page.IsCallBack)

Regards,

Ricky

Hi there,

The difference between a callback and postback is that, as with a postback, a callback does not refresh the currently viewed page (i.e. does not redraw the page). You can think of it as a quick trip back to get some data etc. For example if there were two drop down boxes, the second dependant on the value of the first, when a user selects a value of a the first, rather then posting the whole page, doing some server side calculations and returning a new whole page to the client, a callback can enable you to only go fetch the required data. Obviously from this, View State is not updated with a callback (it's the same instance of the page just updated!!!).

Hope this helps.


Tom thats a good answer to the original posters question. So am I right in thinking callback are the core of the whole AJAX craze. I'm learning ajax at the moment, not ajax.net for just the regular ajax fundamentals and what you've sais about only fetching required date seems to ring a bell.

Also can callaback be implemented without the use of the .net ajax framework?


Hi,

Altough similar in end results to what can be achieved with AJAX (but limited compared to ajax) the callback functionality is not part of its framework and is a feature of just .NET 2.0 (other options avaialble with 1.1). Try the following article for more information it puts the difference between callback functionalty and AJAX into context.

http://www.geekpedia.com/tutorial155_ASP.NET-2.0-Script-CallBack-(Ajax-like).html

Thanks


i dont know it may help you or not... just check out this

This feature allows you to programmatically call server-side methods through client-side JavaScript code without the need for posting back the page.

http://dotnetjunkies.com/Article/E80EC96F-1C32-4855-85AE-9E30EECF13D7.dcik

with good sample


Thanks a lot, Tom.

Ricky.

The directory name is invalid

In VS2005 I drop a button and a dropdownlist on a web form.
When I try to change the name of these (i.e. from Button1 to btnEdit)
in the Properties panel, I get a message popping up saying "The
directory name is invalid." and it won't let me change the
name.
Any Ideas?Actually I had a problem like that once with the Beta program, I closed the
solution, open again and I was able to rename it, what version of the VS2005
are you running and did you try that?
Cheers
Al
"jhcorey@.yahoo.com" wrote:

> In VS2005 I drop a button and a dropdownlist on a web form.
> When I try to change the name of these (i.e. from Button1 to btnEdit)
> in the Properties panel, I get a message popping up saying "The
> directory name is invalid." and it won't let me change the
> name.
> Any Ideas?
>

The directory name is invalid

In VS2005 I drop a button and a dropdownlist on a web form.
When I try to change the name of these (i.e. from Button1 to btnEdit)
in the Properties panel, I get a message popping up saying "The
directory name is invalid." and it won't let me change the
name.
Any Ideas?Actually I had a problem like that once with the Beta program, I closed the
solution, open again and I was able to rename it, what version of the VS2005
are you running and did you try that?

Cheers
Al

"jhcorey@.yahoo.com" wrote:

> In VS2005 I drop a button and a dropdownlist on a web form.
> When I try to change the name of these (i.e. from Button1 to btnEdit)
> in the Properties panel, I get a message popping up saying "The
> directory name is invalid." and it won't let me change the
> name.
> Any Ideas?
>

The dreaded back button

Within an application, is there any way to "tamper" with the history of URLs retained by the browser, so that I can control the URL associated with the back button?

I guess this would entail deleting the last page from the linked list that the browser holds for pages that I do not wish to revisit.

Is this possible?Because of security reasons, you can't get the history from the client.

Tuesday, March 13, 2012

The HTTP verb POST used to access path /WebSite11/HTMLPage.htm is not allowed.]

I got that error message when I clicked a Link Button that had it's PostBackUrl set to HTMLPage.htm.

Any insights?

Thanks,

Dave

Not sure about the error, but if you want to post the data to a normal html-page. Why not use a simple html-submit-button?

<input type="submit" value="Post My Data!" />

Whouldn't that work for you?

The link button is not showingcorrect

I have a datalist. This is the code.
I have 2linkbuttons and it depends of a field to show one or the other.
The IF clause is OK, but its showing me the links in BLACK not in blue! and
they are like plain text not links.
asp:DataList id="dlsolicitud" runat="server" Width="800px"
GridLines="Both" CellPadding="4" BorderColor="#CC9966"
BackColor="White" BorderStyle="None" BorderWidth="1px">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<HeaderTemplate>
<TABLE id="Table2" runat="server" borderColor="#000000"
cellSpacing="1" cellPadding="1"
width="800" border="1" runat="server">
<TR>
<TD width="30">Id</TD>
<TD width="200">Nombre</TD>
<TD width="50">Prioridad</TD>
<TD width="500">Diagnostico</TD>
<TD width="50">Estadl</TD>
<TD width="20"></TD>
</TR>
</TABLE>
</HeaderTemplate>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<ItemTemplate>
<TABLE id="Table2" borderColor="#000000" cellSpacing="1"
cellPadding="1" width="800" border="1"
runat="server">
<TR>
<TD width="30"><%# DataBinder.Eval(Container,
"DataItem.idserviciomantenimiento") %></TD>
<TD width="200"><%# DataBinder.Eval(Container,
"DataItem.nombre") %></TD>
<TD width="50"><%# DataBinder.Eval(Container,
"DataItem.prioridad") %></TD>
<TD width="500"><%# DataBinder.Eval(Container,
"DataItem.diagnostico") %></TD>
<TD width="50"><%# DataBinder.Eval(Container, "DataItem.estado")
%></TD>
<TD width="20">
<asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
CommandName="Ejecutar">Ejecutar</asp:linkbutton>
<asp:linkbutton Runat="server" ID="finalizar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
CommandName="Finalizar">Finalizar</asp:linkbutton>
</TD>
</TR>
</TABLE>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
</asp:DataList>
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 1.
MIEMBRO ACTIVO DE ALIANZADEVfor an anchor (what a link button renders as), you need to set the following
styles:
a :visted
a :link
a :active
a :hover
to control the display
-- bruce (sqlwork.com)
"Luis Esteban Valencia" <luisvalen@.haceb.com> wrote in message
news:uF2ZcbRkEHA.556@.tk2msftngp13.phx.gbl...
> I have a datalist. This is the code.
> I have 2linkbuttons and it depends of a field to show one or the other.
> The IF clause is OK, but its showing me the links in BLACK not in blue!
and
> they are like plain text not links.
> asp:DataList id="dlsolicitud" runat="server" Width="800px"
> GridLines="Both" CellPadding="4" BorderColor="#CC9966"
> BackColor="White" BorderStyle="None" BorderWidth="1px">
> <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
> BackColor="#FFCC66"></SelectedItemStyle>
> <HeaderTemplate>
> <TABLE id="Table2" runat="server" borderColor="#000000"
> cellSpacing="1" cellPadding="1"
> width="800" border="1" runat="server">
> <TR>
> <TD width="30">Id</TD>
> <TD width="200">Nombre</TD>
> <TD width="50">Prioridad</TD>
> <TD width="500">Diagnostico</TD>
> <TD width="50">Estadl</TD>
> <TD width="20"></TD>
> </TR>
> </TABLE>
> </HeaderTemplate>
> <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
> <ItemTemplate>
> <TABLE id="Table2" borderColor="#000000" cellSpacing="1"
> cellPadding="1" width="800" border="1"
> runat="server">
> <TR>
> <TD width="30"><%# DataBinder.Eval(Container,
> "DataItem.idserviciomantenimiento") %></TD>
> <TD width="200"><%# DataBinder.Eval(Container,
> "DataItem.nombre") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
> "DataItem.prioridad") %></TD>
> <TD width="500"><%# DataBinder.Eval(Container,
> "DataItem.diagnostico") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
"DataItem.estado")
> %></TD>
> <TD width="20">
> <asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
> CommandName="Ejecutar">Ejecutar</asp:linkbutton>
> <asp:linkbutton Runat="server" ID="finalizar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
> CommandName="Finalizar">Finalizar</asp:linkbutton>
> </TD>
> </TR>
> </TABLE>
> </ItemTemplate>
> <FooterStyle ForeColor="#330099"
BackColor="#FFFFCC"></FooterStyle>
> <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
> BackColor="#990000"></HeaderStyle>
> </asp:DataList>
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 1.
> MIEMBRO ACTIVO DE ALIANZADEV
>

The link button is not showingcorrect

I have a datalist. This is the code.
I have 2linkbuttons and it depends of a field to show one or the other.

The IF clause is OK, but its showing me the links in BLACK not in blue! and
they are like plain text not links.

asp:DataList id="dlsolicitud" runat="server" Width="800px"
GridLines="Both" CellPadding="4" BorderColor="#CC9966"
BackColor="White" BorderStyle="None" BorderWidth="1px">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<HeaderTemplate>
<TABLE id="Table2" runat="server" borderColor="#000000"
cellSpacing="1" cellPadding="1"
width="800" border="1" runat="server">
<TR>
<TD width="30">Id</TD>
<TD width="200">Nombre</TD>
<TD width="50">Prioridad</TD>
<TD width="500">Diagnostico</TD>
<TD width="50">Estadl</TD>
<TD width="20"></TD>
</TR>
</TABLE>
</HeaderTemplate>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<ItemTemplate>
<TABLE id="Table2" borderColor="#000000" cellSpacing="1"
cellPadding="1" width="800" border="1"
runat="server">
<TR>
<TD width="30"><%# DataBinder.Eval(Container,
"DataItem.idserviciomantenimiento") %></TD>
<TD width="200"><%# DataBinder.Eval(Container,
"DataItem.nombre") %></TD>
<TD width="50"><%# DataBinder.Eval(Container,
"DataItem.prioridad") %></TD>
<TD width="500"><%# DataBinder.Eval(Container,
"DataItem.diagnostico") %></TD>
<TD width="50"><%# DataBinder.Eval(Container, "DataItem.estado")
%></TD>
<TD width="20">
<asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
CommandName="Ejecutar">Ejecutar</asp:linkbutton>
<asp:linkbutton Runat="server" ID="finalizar" visible='<%#
iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
CommandName="Finalizar">Finalizar</asp:linkbutton>
</TD>
</TR>
</TABLE>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
</asp:DataList
--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 1.
MIEMBRO ACTIVO DE ALIANZADEVfor an anchor (what a link button renders as), you need to set the following
styles:

a :visted
a :link
a :active
a :hover

to control the display

-- bruce (sqlwork.com)

"Luis Esteban Valencia" <luisvalen@.haceb.com> wrote in message
news:uF2ZcbRkEHA.556@.tk2msftngp13.phx.gbl...
> I have a datalist. This is the code.
> I have 2linkbuttons and it depends of a field to show one or the other.
> The IF clause is OK, but its showing me the links in BLACK not in blue!
and
> they are like plain text not links.
> asp:DataList id="dlsolicitud" runat="server" Width="800px"
> GridLines="Both" CellPadding="4" BorderColor="#CC9966"
> BackColor="White" BorderStyle="None" BorderWidth="1px">
> <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
> BackColor="#FFCC66"></SelectedItemStyle>
> <HeaderTemplate>
> <TABLE id="Table2" runat="server" borderColor="#000000"
> cellSpacing="1" cellPadding="1"
> width="800" border="1" runat="server">
> <TR>
> <TD width="30">Id</TD>
> <TD width="200">Nombre</TD>
> <TD width="50">Prioridad</TD>
> <TD width="500">Diagnostico</TD>
> <TD width="50">Estadl</TD>
> <TD width="20"></TD>
> </TR>
> </TABLE>
> </HeaderTemplate>
> <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
> <ItemTemplate>
> <TABLE id="Table2" borderColor="#000000" cellSpacing="1"
> cellPadding="1" width="800" border="1"
> runat="server">
> <TR>
> <TD width="30"><%# DataBinder.Eval(Container,
> "DataItem.idserviciomantenimiento") %></TD>
> <TD width="200"><%# DataBinder.Eval(Container,
> "DataItem.nombre") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
> "DataItem.prioridad") %></TD>
> <TD width="500"><%# DataBinder.Eval(Container,
> "DataItem.diagnostico") %></TD>
> <TD width="50"><%# DataBinder.Eval(Container,
"DataItem.estado")
> %></TD>
> <TD width="20">
> <asp:linkbutton Runat="server" ID="ejecutar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="ENVIADO",1,0) %>'
> CommandName="Ejecutar">Ejecutar</asp:linkbutton>
> <asp:linkbutton Runat="server" ID="finalizar" visible='<%#
> iif(DataBinder.Eval(Container, "DataItem.Estado")="EN EJECUCION",1,0) %>'
> CommandName="Finalizar">Finalizar</asp:linkbutton>
> </TD>
> </TR>
> </TABLE>
> </ItemTemplate>
> <FooterStyle ForeColor="#330099"
BackColor="#FFFFCC"></FooterStyle>
> <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
> BackColor="#990000"></HeaderStyle>
> </asp:DataList>
>
> --
> LUIS ESTEBAN VALENCIA
> MICROSOFT DCE 1.
> MIEMBRO ACTIVO DE ALIANZADEV

The magical button? Declarative parameters tutorial

Hey folks,

Long time follower, first time poster.

I'm going through the"Working with Data in ASP.NET 2.0" tutorials, and this one bit has me mystified.

Page 4-6 (or about half way down, section "Setting the Parameter Value to the Property Value of a Web Control"

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

I've been through all the steps, and they all work - I just don't understand why. The mystery lies in the "Show suppliers" button. How does
my datagrid know I have clicked this button? How can it figure out, by this button click, to grab what's in the textfield, and send to the datagrid?

I haven't specified any code on the "on click" event for the button, and the markup source doesn't seem to reveal any kind of relationship between the textfield and the button.
If I put more buttons on the form, they all seem to behave in the same way - populating the datagrid.

Magic?

I believe you will find the answer to that question in this part of Scott's tutorial:

When visiting the page for the first time the CountryName TextBox is empty. The ObjectDataSource's Select method is still invoked by the GridView, but a value of null is passed into the GetSuppliersByCountry(country) method. The TableAdapter converts the null into a database NULL value (DBNull.Value), but the query used by the GetSuppliersByCountry(country) method is written such that it doesn't return any values when a NULL value is specified for the @.CategoryID parameter. In short, no suppliers are returned.

Once the visitor enters in a country, however, and clicks the Show Suppliers button to cause a postback, the ObjectDataSource's Select method is requeried, passing in the TextBox control's Text value as the country parameter.


tmorton:


Once the visitor enters in a country, however, and clicks the Show Suppliers button to cause a postback, the ObjectDataSource's Select method is requeried, passing in the TextBox control's Text value as the country parameter.

Thanks for the reply. I'm figuring the operative here is "postback" - the button causes a postback, but I still can't see the relationship between the button's postback, the textfield, and the datagrid.

My appoligies for newbie-ness, but I'm really trying to understand the workings of ASP.NET, coming from a Java Swing world, everything is new to me!Confused


mortdk:

Thanks for the reply. I'm figuring the operative here is "postback" - the button causes a postback, but I still can't see the relationship between the button's postback, the textfield, and the datagrid.


Hi there,

The relation is set when you configure the newly created ObjectDataSource, see in Figure 8, where the parameter source is set to a "control" and then you specify that the ID of the control to use is "CountryName". CountryName is the textbox and effectivly what you're doing is to tell the method the ObjectDataSource is calling (GetSuppliersByCountry()) to use the value from the "CountryName" text box as the value to pass along to the method.

You can physically see this in the markup (in the code view of your .aspx page) as shown in the code between Figure 8 and 9 of the article, in the ControlParameters tag inside the SelectParameters you can see that the ControlID is set to the ID of the text box and the type and property are set to string/text.

Hopefully this makes senseSmile


mortdk:

Thanks for the reply. I'm figuring the operative here is "postback" - the button causes a postback, but I still can't see the relationship between the button's postback, the textfield, and the datagrid.

Well, I doubt that I can do a better job at explaining things than Scott Mitchell can, but I'll give it a go. :-) For reference, here is the pertinent part of the DelcarativeParameters.aspx page:

<h3>View Suppliers By Country</h3>
<p>
Enter a country:
<asp:TextBox ID="CountryName" runat="server"></asp:TextBox> <asp:Button ID="Button1"
runat="server" Text="Show Suppliers" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="SupplierID"
DataSourceID="ObjectDataSource2" EnableViewState="False">
<Columns>
<asp:BoundField DataField="CompanyName" HeaderText="Company" SortExpression="CompanyName" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetSuppliersByCountry" TypeName="SuppliersBLL" UpdateMethod="UpdateSupplierAddress">
<UpdateParameters>
<asp:Parameter Name="supplierID" Type="Int32" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="city" Type="String" />
<asp:Parameter Name="country" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="CountryName" Name="country" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

On that page you have 4 server controls coming into play for the "View Suppliers by Country" functionality:

Textbox (ID=CountryName)

Button (ID=Button1)

GridView (ID=GridView1)

ObjectDataSource (ID=ObjectDataSource2)

As you can see, GridView1's DataSource is ObjectDataSource2. That means that GridView1's data comes from the data supplied by ObjectDataSouce2's SelectMethod, which is method GetSuppliersByCountry. Any parameters needed by that method are passed into it from the ObjectDataSource's SelectParameters. In this case, there is one SelectParameter, and a ControlParameter is being used. This means that the value stored in a server control is used as the parameter value. The server control whose value is being passed is the CountryName Textbox.

So, the first time this page is accessed, the CountryName Textbox does not hold any value. The GridView asks the ObjectDataSource to load it up with data, the ObjectDataSource uses the CountryName value as a parameter to the GetSuppliersByCountry method, and since the CountryName is empty, the method returns no results. As a result, the GridView is empty.

Now, when the site visitor keys a value into the CountryName Textbox, and presses the button, the button causes a postback since it is a server control. So, once again, the GridView asks the ObjectDataSource to load it up with data, the ObjectDataSource uses the CountryName value as a parameter to the GetSuppliersByCountry method. This time, the CountryName is not empty, so the method returns results, and the GridView is populated.

Does this help at all?


Thanks for the excelent explanations. I understand the bindingbetween the textfield and the datagrid, this seems logical - take theCountryName.Text and use this as a parameter to look for data. Myproblem is understanding how the button1 can know anything about anytextfields or datagrids, when I haven't told it to do anything. All Idid was drop a button on the form, and it works "out of the box".

Now, when the site visitor keys a value into the CountryName Textbox,and presses the button, the button causes a postback since it is aserver control. So, once again, the GridView asks the ObjectDataSourceto load it up with data,

After fiddling a little with the tutorial, however odd I find the behavior, I think I might understand... please, correct me if I'm wrong:

The button only causes a postback. It's the postback that actually triggers the "reload" of the datasouce? I've tried with a LinkButton, a CheckBox (set to postback), and they all trigger a reload. Maybe it's just the tutorial's simplicity that caught me off guard. What if I have 3 other controls on the form that also need to perform postbacks, but must not change the contents of the mentioned gridview?

tmorton:

Now, when the site visitor keys a value into the CountryName Textbox, and presses the button, the button causes a postback since it is a server control. So, once again, the GridView asks the ObjectDataSource to load it up with data, the ObjectDataSource uses the CountryName value as a parameter to the GetSuppliersByCountry method.


Looks like I mucked up the quotes - sorry, hope you can decipher.

mortdk:

After fiddling a little with the tutorial, however odd I find the behavior, I think I might understand... please, correct me if I'm wrong:

The button only causes a postback. It's the postback that actually triggers the "reload" of the datasouce? I've tried with a LinkButton, a CheckBox (set to postback), and they all trigger a reload. Maybe it's just the tutorial's simplicity that caught me off guard. What if I have 3 other controls on the form that also need to perform postbacks, but must not change the contents of the mentioned gridview?

Sounds like you've got the hang of how the postback gets triggered and the data getting loaded.

In regards to having other controls that also trigger postbacks on a page, keeping the value of a control in ASP.NET is done with something called viewstate. If you enable viewstate on a control the values will get stored in a hidden field and then used to re-populate the control after the postback. I'm no expert on the use of viewstate but I guess in the example case, you could enable viewstate for the country textbox so that it keeps the value you input and therefore use that value as a parameter again after the postback. Or you could just enable viewstate on the gridview, I think both ways has positives and negatives.

More info on viewstate:

http://aspalliance.com/909

http://www.extremeexperts.com/Net/Articles/ViewState.aspx