Results 1 to 17 of 17

Thread: IsPostBack issues

Threaded View

  1. #1

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    IsPostBack issues

    I have this code on my asp.net page in page load event:
    vb.net Code:
    1. If Not IsPostBack Then
    2.     recordId = Request.QueryString("rid")
    3.     myRecord = GetRecord(recordId)
    4.     If myRecord Is Nothing Then
    5.         ShowErrorMessage("Record not found!")
    6.         ' pnlMainBody.Visible = False
    7.         Exit Sub
    8.     End If
    9.     ViewState("RecordId") = recordId
    10. Else
    11.     recordId = ViewState("RecordId").ToString
    12. End If
    and this javascript code:
    javascript Code:
    1. function GotoRecord() {
    2.     var tb = document.getElementById('txtRecordNumber');
    3.     if (isNaN(tb.value) || tb.value.indexOf('.') >= 0) {
    4.         tb.focus();
    5.         alert("Enter valid Record Number.");
    6.     }
    7.     else
    8.         window.location = 'ShowRecord.aspx?rid=' + tb.value;
    9. }

    It works fine until the "pnlMainBody.Visible = False" is commented out and shows the message ""Record not found!" correctly. But if I uncomment that line, it believes that it is a postback and enters the ELSE block and errors out, when user enters some record number in the textbox and hits enter (it executes the javascript code)

    Any ideas?
    Last edited by Pradeep1210; Dec 21st, 2010 at 06:51 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width