Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 27th, 2006, 07:20 PM
Authorized User
Points: 514, Level: 8
Points: 514, Level: 8 Points: 514, Level: 8 Points: 514, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Postback and Gridview refresh

I'm using javascript to capture information associated with a Gridview and put in hidden fields.

I want to now:

A) Send the page back to the server, using javascript
B) In the codebehind
   1) react to the page return
   2) extract the hidden fields and update the gridview source
   3) initiate a refresh on the gridview

I don't know how to do A, B1 and B3.

Any guidance on how to do these things would be appreciated.

Thanks!
Reply With Quote
  #2 (permalink)  
Old February 27th, 2006, 10:58 PM
Authorized User
Points: 514, Level: 8
Points: 514, Level: 8 Points: 514, Level: 8 Points: 514, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah...I learned that I could just do a form.submit for A), and pick up the hidden fields in Page_Load (with a judicious use of IsPostBack and value tests).

So the remaining issue is B3.
Reply With Quote
  #3 (permalink)  
Old February 28th, 2006, 01:37 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

If you figured out A. then the gridview should refresh. I assume you use a forms(0).submit(); to submit the page. If so, then the gridview should refresh, unless you included the code with in the if not ispostback statement.

Jim

Reply With Quote
  #4 (permalink)  
Old February 28th, 2006, 01:19 PM
Authorized User
Points: 514, Level: 8
Points: 514, Level: 8 Points: 514, Level: 8 Points: 514, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.

Here are the key code elements:

=================the key page elements (other than the gridview, which is generated entirely from the designer)

       <asp:HiddenField ID="Hidden1" runat="server" value = ""/>
        <input id="Button1" type="button" style="z-index:103; left: 180px; position: absolute; top: 8px;" onClick="javascript:Button1Click()" value="button" />
        <input id="Text1" style="z-index: 104; left: 16px; position: absolute; top: 8px"
        type="text" />
============client code

<script language=javascript>
//-------------------------
function GetElem(varString){return document.getElementById(varString) }
//-------------------------
function Button1Click() {
    //alert(GetElem("Hidden1").value)
    alert("text1 = " + GetElem("Text1").value);
    GetElem("Hidden1").value = GetElem("Text1").value
    alert("Hidden1 = " + GetElem("Hidden1").value);
    document.forms[0].submit();
    }
 alert ("set hidden1 to blank")
 GetElem("Hidden1").value = ""
 </script>


===============code behind

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            If Me.Hidden1.Value.Trim <> "" Then
                MsgBox("updating at server " & Me.Hidden1.Value)
                Dim DB As New DB 'the database maintenance class
                Call DB.AddRecord(Me.Hidden1.Value)
                Me.Hidden1.Value = ""
            End If
        End If
    End Sub

=================================

The DB gets updated...I can see the new record in the table, and the gridview will show it if I recompile.

However,the gridview doesn't refresh, even on a page refresh.

Also, for some reason the value of "Hidden1" doesn't get reset to blanks, so on each page load, it sees a non-blank value in Hidden1, and updates the database again.

Any insight on these points would be appreciated.

Thanks!
Reply With Quote
  #5 (permalink)  
Old February 28th, 2006, 01:57 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I think your update is happening AFTER the grid binds, and that's why you are not seeing the updated records. As for the Hidden1 field, it looks like it should work.

Reply With Quote
  #6 (permalink)  
Old February 28th, 2006, 04:33 PM
Authorized User
Points: 514, Level: 8
Points: 514, Level: 8 Points: 514, Level: 8 Points: 514, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the input.

I got it to work, except for the fact that it doesn't seem to clear out the hidden1 value, so keeps re-adding to the db with each page refresh. But I don't think that's a gridview refresh issue, so I'm going to try to isolate it and figure it out separately.

Here's the solution I arrived at (with thanks to several parties in different forums for promptings that eventually got me to this.)

=====key page elements (except completely vanilla gridview, created in designer, and form1 method = "post")

<input type=hidden id="Hidden1" runat=server value = "" />
<input id="Button1" type="button" style="z-index:103; left: 180px; position: absolute; top: 8px;" onClick="javascript:Button1Click()" value="button" />
<input id="Text1" style="z-index: 104; left: 16px; position: absolute; top: 8px" type="text" />

===========javascript
<script>
function Button1Click() {
    document.form1.Hidden1.value = document.form1.Text.value
    document.forms[0].submit(); // not very complicated here...a nice surprise
    }
</script>

===========codebehind

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsPostBack Then
            If Trim(Me.Hidden1.Value) <> "" Then ' the re-add hidden1 gets past this :-/
                Dim DB As New DB
                Call DB.AddRecord(Me.Hidden1.Value) ' the db update method
                Me.Hidden1.Value = "" ' the re-add gets past this, too :-/
                Me.GridView1.DataBind() ' this was the missing piece for a while
            End If
        End If

    End Sub
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Refresh on first postback slim182 ASP.NET 2.0 Basics 4 February 20th, 2007 08:22 PM
Refresh GridView Using Refresh Button msbsam ASP.NET 2.0 Professional 0 December 6th, 2006 05:57 AM
Updating DataGrid without PostBack/Refresh Baby_programmer ASP.NET 1.0 and 1.1 Professional 13 April 11th, 2005 04:47 AM
Refresh DataGrid without PostBack Baby_programmer Classic ASP XML 1 April 2nd, 2005 04:22 AM
Refresh a combobox without postback Eddy ASP.NET 1.x and 2.0 Application Design 1 March 10th, 2004 12:34 AM



All times are GMT -4. The time now is 05:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.