Client side solution?

Last post 04-10-2008 1:54 PM by Ganesh@Nilgris. 8 replies.

Sort Posts:

  • Client side solution?

    04-09-2008, 5:51 AM
    • Loading...
    • dbrook007
    • Joined on 10-30-2006, 8:59 PM
    • Posts 38

    I have a problem at the moment with a web project.

    I have two Panels within an UpdatePanel on an aspx page (using Masterpages).  I'm using ASP.Net 2.0 with an AJAX enabled website.

    The two Panels represent a Master-Detail type relationship.  I want a user to click a LinkButton in the first Panel and then for the 2nd Panel to be displayed with the detail.

    However, I need to set some text properties of textboxes programmatically when the LinkButton is clicked.

    The problem, though, is that the UpdatePanel's Load event fires BEFORE the LinkButton's click event.  The data needs to be in the textboxes before the UpdatePanel's Load event fires, as it renders items depending upon this data.

    I was wondering if a client-side solution might work?

    Is there a way I could wire the "OnClientClick" of the LinkButton to a client-side JavaScript function that would write the appropriate text to a hidden field or other control or variable that could be then read in the code behind when the UpdatePanel's Load event fires?

    Or, is there an easier or better way of doing this?  Am I missing something on the event sequence for the UpdatePanel??

    Any help much appreciated on this.

    Thanks - Darren

     

     

    Darren Brook
    e: darrenbrook@btconnect.com
    Filed under: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
  • Re: Client side solution?

    04-09-2008, 1:11 PM

    i tried u re logic and what the page works depends on the page life cycle

    Consider the below code

    Protected Sub updatepanel_load(ByVal sender As Object, ByVal e As System.EventArgs)

    TextBox2.Text = "world"

    End Sub

    Protected Sub linkbutton_click(ByVal sender As Object, ByVal e As System.EventArgs)

    TextBox1.Text = "hello"

    End Sub

    Protected Sub linkbutton_init(ByVal sender As Object, ByVal e As System.EventArgs)

    TextBox2.Text = "hello world"

    End Sub

    I have use the "init" property of linkbutton just to call before the upload event is called. Just check if this helps to solve your problem

     

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
  • Re: Client side solution?

    04-10-2008, 5:18 AM
    • Loading...
    • dbrook007
    • Joined on 10-30-2006, 8:59 PM
    • Posts 38

    In my project, I have HTML markup that sets the CommandArgument property of the LinkButton to a unique ID string (which identifies an item in the underlying data).

    As the LinkButton is in the Itemtemplate of a GridView, each LinkButton CommandArgument shall contain a unique ID.

    So, I'm using the CommandArgument just as a generic store for these unique IDs.  This may not be the best way to go about this??

    The init event does not have the CommandArgument data value when it fires.  This data is needed to store in a hidden field (or ViewState/Session variable).

    When I tested it, the Init event fires before the page_load event on a partial page postback.  However, the Init event still fires after the postback.  The  CommandArgument data is not present in the Init event after the postback.

    I am wondering if there is an easier way to achieve what I want?

         

     

    Darren Brook
    e: darrenbrook@btconnect.com
  • Re: Client side solution?

    04-10-2008, 5:26 AM

     

    what i guess from your answer is - that u have a gridview in a panel which contains linkbuttton as a a field. What u expect is something like clicking on the linbutton should fetch a detailsview in another panel. Is this is what u are looking for ??

     

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
  • Re: Client side solution?

    04-10-2008, 5:54 AM
    • Loading...
    • dbrook007
    • Joined on 10-30-2006, 8:59 PM
    • Posts 38

    Yes...

    The linkbutton is in the ItemTemplate of the gridview on each row.

    The gridview is in a Panel which is in an UpdatePanel.  This is the "master" view, containing a list of data items.  The UpdatePanel also contains another Panel.  This second panel is the details view, which should display the details of a selected item the user picks from the first panel.

    But, both the panels in the UpdatePanel reside in the same space.  So, when the user selects an item, the master panel becomes invisible and the details panel is in view.

    As you said, I want to click on the link button and then view the details in another panel, with the master panel becoming invisible.

     

     

    Darren Brook
    e: darrenbrook@btconnect.com
  • Re: Client side solution?

    04-10-2008, 6:09 AM
    • Loading...
    • dbrook007
    • Joined on 10-30-2006, 8:59 PM
    • Posts 38

    The problem is how to let the details panel know the unique id of the data item that's been selected from the gridview in the 1st panel.

     

    Darren Brook
    e: darrenbrook@btconnect.com
  • Re: Client side solution?

    04-10-2008, 10:51 AM

     

    I have used hyperlinkfield instead of linkbutton. I have 2 tables namely "master" and "details". I hope this could give u the desired result.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>

    <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="rollno">

    <Columns>

    <asp:HyperLinkField DataTextField ="rollno" DataNavigateUrlFields="rollno" DataNavigateUrlFormatString = "default.aspx?id={0}" />

    <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

    </Columns>

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:classConnectionString %>"

    SelectCommand="SELECT [rollno], [name] FROM [master]"></asp:SqlDataSource>

    </asp:Panel>

    <br />

    <asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">

     

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:classConnectionString %>"

    SelectCommand="SELECT [rollno], [maths] FROM [details] WHERE ([rollno] = @rollno)">

    <SelectParameters>

    <asp:QueryStringParameter Name="rollno" QueryStringField="id" Type="Int32" />

    </SelectParameters>

    </asp:SqlDataSource>

    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">

    <Columns>

    <asp:BoundField DataField="rollno" HeaderText="rollno" SortExpression="rollno" />

    <asp:BoundField DataField="maths" HeaderText="maths" SortExpression="maths" />

    </Columns>

    </asp:GridView>

    </asp:Panel>

    </ContentTemplate>

    </asp:UpdatePanel>

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
  • Re: Client side solution?

    04-10-2008, 12:57 PM
    • Loading...
    • dbrook007
    • Joined on 10-30-2006, 8:59 PM
    • Posts 38

    First of all, thanks for your help and advice so far - much appreciated.

    The project I am working on is a little different in that an XML datasource is being used via a bespoke provider, so I can't quite link things up the way described above.  However, I have tried this with the appropriate adjustment, using the HyperLinkField.

    What you have kindly suggested certainly works.  However, it does not look like it's a suitable solution as there is a more general issue in that this is an AJAX enabled website.

    The idea of the UpdatePanel, and the two normal Panels within, is that the transition should be visibly seamless between viewing a list of data items in the master view (in the 1st panel) and the details of a particular selected item in the details view (the 2nd panel).

    In other words, it relies upon a partial page postback on the UpdatePanel.

    However, when the link for a hyperlink control or hyperlinkfield is clicked, the page is requested as a completely new request and therefore does not cause a postback to occur.  This results in the whole page loading again, which is not what is desired here.

    I appreciate I should have mentioned this before and apologise for this.... it just did not occur to me.

    The project also uses a masterpage. 

    The UploadPanel has both Load() and PreRender() events.  Within these events is the code that determines which panel is displayed upon a partial page postback.  So, prior to the content of these event handlers executing, I need to determine which item was selected from the GridView (each item in the Grid is identified by a unique string ID).

    I am now struggling a little with this one.  I've been through a few books and am still not getting anywhere.  Frustrating.

    Do you have any other ideas on this? 

    Thanks - Darren

    Darren Brook
    e: darrenbrook@btconnect.com
  • Re: Client side solution?

    04-10-2008, 1:54 PM
    Answer

     

    actaully i used linkbutton and i had the row_datacommand of the gridview. below is the piece of code in templatefield

    <asp:linkbutton id="linbutton1" runat="server" Text = '<%# Eval("rollno") %>' CommandArgument =  '<%# Eval("rollno") %>'  />

    and in the row databound of the gridview i have the following code

    {

     int i = convert.toint32(e.commandArgument); -> i am able to get the value of "i" here but i did not find way to pass this parameter to the "details" table

    that is the reason i have used the hyperlinkfield

     

    }

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.
Page 1 of 1 (9 items)
Microsoft Communities
Page view counter