Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

position like an anchor after postback.

Status
Not open for further replies.

lin73

Programmer
Feb 17, 2006
110
SE
Hi

I have a aspx page with some radiobuttonlist on, they all have autopostback on them. My question is, is it possible to load the page back to where the radiobutton list selection where made after the postback have been done?


Regards
 
put an anchor tag around the radio buttons.
in the code behind create a simple function to register a startup script which will point to the anchor. like
private void GoTo(string anchor)
{
// create simple js goto anchor script.
page.clientscript.registerstartupscript(...);
}

then in the event of each radio button call GoTo("myAnchor"); when the page completes the post back it will go to that anchor.

If your using asp.net 2.0 you could also look into the AJAX library with an updatepanel.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Also, in the version 2.0 of the framework, controls have a Focus method that you may be able to utilise.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi

I ended up with this page attribute ...

MaintainScrollPositionOnPostback="true"

And it workd wonderfull :)


Regards
 
FYI: this only works with IE.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I got it working in firefox 2.02...

I would rather used the updatepanel, but the problem I then face is...

Radiobuttonlist1 is required, and when Radiobuttonlist1 index 2 is selected the Radiobuttonlist2 should be required, but since there is no postback I can't enable the requiredfield validator for Radiobuttonlist2 when the Radiobuttonlist1 index 2 has been selected.


Any ideas what I can do about that?
 
you also need to wrap the other required fields in their own update panel and set the activation to the trigger when the validation occurs.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
hmm, I have placed Radiobuttonlist1 and Radiobuttonlist2 in updatepanel1, and then I placed the requiredfield validator for Radiobuttonlist2 in the updatepanel2. Then I placed a trigger in the updatepanel2 like this...

<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />

But that doesn't help. Was that the way you meant?


Regards
 
lin73 said:
Radiobuttonlist1 is required, and when Radiobuttonlist1 index 2 is selected the Radiobuttonlist2 should be required, but since there is no postback I can't enable the requiredfield validator for Radiobuttonlist2 when the Radiobuttonlist1 index 2 has been selected
looking back at your statement what exactly to you mean by [tt]enable the requiredfield validator[/tt]? does the error message not display? does the validation not execute? something else?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi jason

When the page load the Radiobuttonlist1, Requiredfieldvalidator1 are enabled, but the Radiobuttonlist2 and requiredfieldvalidator2 is not enabled

Radiobuttonlist1 have 5 selections that can be made, and you must select one of them, if you select index 2 Radiobuttonlist2 and requiredfieldvalidator 2 should be enabled. so if you select index 2 in Radiobuttonlist1 there should be a validation by the requiredfield validator2 to check that something is being selected from radiobuttonlist2. But that doesn't happened.

Hope this sort things out.
 
so if you select option 2 from RBL1 RBL2 appears. then submit the form, without selecting a value for RBL2, and RFV2 does not execute?
But all of this works if AJAX is removed?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
do you use a validation summary? if so this will also need an updatepanel so the error messages can be displayed.

the problem may also be the order of events firing (although I doubt this since the process works without AJAX).

can you post the code?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason

If I remove the validation summary it works, but if I have it on the page only rbl1 validation pop up. Heres my code...

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <br />
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                    <asp:ListItem>1</asp:ListItem>
                    <asp:ListItem>2</asp:ListItem>
                    <asp:ListItem>3</asp:ListItem>
                </asp:RadioButtonList>
                <asp:RadioButtonList ID="RadioButtonList2" runat="server" Enabled="False">
                    <asp:ListItem>a</asp:ListItem>
                    <asp:ListItem>b</asp:ListItem>
                    <asp:ListItem>c</asp:ListItem>
                </asp:RadioButtonList>
            </ContentTemplate>
        </asp:UpdatePanel>
        &nbsp;
        <br />
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
                <asp:RequiredFieldValidator ControlToValidate="RadioButtonList1" ID="RequiredFieldValidator1" runat="server" ErrorMessage="rbl 1 is required" Display="Dynamic"></asp:RequiredFieldValidator>
                <asp:RequiredFieldValidator  Enabled="false" ControlToValidate="RadioButtonList2" ID="RequiredFieldValidator2" runat="server" ErrorMessage="rbl 2 is required" Display="Dynamic"></asp:RequiredFieldValidator>&nbsp;
            </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
        <br />
        <br />
    
    </div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>
</body>
</html>

codebehind..

Code:
Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If RadioButtonList1.SelectedIndex = 2 Then
            RadioButtonList2.Enabled = True
            RequiredFieldValidator2.Enabled = True
        Else
            RadioButtonList2.Enabled = False
            RequiredFieldValidator2.Enabled = False
        End If
    End Sub
End Class
 
things to try:
1. only use one, all inclusive updatepannel for the RBLs and RFVs instead of 2 panels.
2. remove the [tt]Display="Dynamic"[/tt] attribute from the RFVs.
3. set the updatepannel's mode to [tt]conditional[/tt] if your going to use triggers.
4. use the visible property instead of the enabled property for RBL2 and RFV2

If you add a validation summary this will need to be included in the existing update pannel.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top