|
Subject:
|
ANCHOR
|
|
Posted By:
|
collie
|
Post Date:
|
12/16/2003 8:30:00 AM
|
I have a page where the user enters his details and then clicks the save button. If there are errors in the user's details a repeater appears at the bottom of the page with the list of errors. I want the scrollbar to be positioned where the repeater is as otherwise the user might not notice the repeater. Where must i put the line Response.Redirect("paydetails.aspx?#anch")? I have tried putting it in a few places in my code but i was not successful.It takes me back to the default.aspx.
aspx.vb Private Sub SaveOrderData()
'update fields If Order Is Nothing Then Response.Write("No Order") Exit Sub Else Order.PayOrderType = CType(drpCPay.SelectedValue, YBayTools.PayOrder.PayOrderTypeEnum) Order.CardType = drpCCType.SelectedItem.Value
End If
Order.ValidateValues = False If Not Order.Validate() Then
Repeater2.DataSource = Order.ErrorDescription()
Repeater2.DataBind() Exit Sub Else
Repeater2.Visible = False
End If If Not Order.SaveOrder Then Session("sysError") = Order.strSysError Response.Redirect("sysError.aspx")
Else PopulateFields() End If End Sub
aspx: <a name="anch"></a> <TABLE id="Table2" style="Z-INDEX: 101; LEFT: 336px; POSITION: absolute; TOP: 500px" cellSpacing="1" cellPadding="1" width="300" bgColor="#ffff33" border="1"> <asp:repeater id="Repeater2" runat="server"> <HeaderTemplate> <tr> <td align="center" dir="rtl" bgcolor="#ff3333"><font color="#0033cc" size="4"> נמצאו שגיאות בהקלדת נתונים. <br> להלן רשימת השגיאות:</font> </td> </tr> </HeaderTemplate> <ItemTemplate> <TR> <TD align="right" dir="rtl"><font color="#0033cc"><%#Container.DataItem%><br> </font> </TD> </TR> </ItemTemplate> </asp:repeater></TABLE> </body>
|
|
Reply By:
|
stu9820
|
Reply Date:
|
12/16/2003 8:46:47 AM
|
You don't need the '?' in your redirect.
Response.Redirect("paydetails.aspx#anch")
Try that and place where ever you detect the error.
|
|
Reply By:
|
planoie
|
Reply Date:
|
12/16/2003 10:27:22 AM
|
When your page posts back, it's always going to post back to the url that is in the browser. Unfortunately, you can't (easily) modify the URL that the page is posting to. Furthermore, in your scenario that wouldn't be useful anyway as you aren't determining the validation of the form until you are already processing the postback.
Response redirect is probably not what you want either. If you redirect, you are going to loose the modifications the user has made within the form.
Some browsers implement the "scrollIntoView" method. You could write out a little javascript when you detect errors and show the repeater. The javascript should look something like this:
document.getElementById['controlID'].scrollIntoView();
You need to replace controlID with the complete unique control ID from .net. Get it with Repeater2.ClientID in your ASP code. Use RegisterStartUpScript() in .net to get the script chunk on the page (More info on RegisterStartUpScript()). You must include the start and end script tags when you call that method.
Take a look on google for links to details on scrollIntoView().
PS. Using "Exit Sub" is considered bad form by many programmers. It can make applications extremely hard to troubleshoot
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
collie
|
Reply Date:
|
12/17/2003 2:43:40 AM
|
Hi,
Thanks guys for the help. I did as Peter suggested and it works but i had to add an input type hidden. If i referred to document.getElementById("Repeater2").scrollIntoView(); then it gave me that the object is empty. Is that perhaps because it appears only if there is an error? Referring to the hidden field works: document.getElementById("hidden").scrollIntoView();
|