problem with postback

H

Harry

Hi,

This aspx page (let's call it thispage.aspx) fetches data from a
sqldatasource, then performs several things (in code-behind) and, to
simplify, passes data from code-behind via a hiddenfield to a javascript in
the aspx file. This javascript performs things and finally send data via a
form to another database.

My problem is that when the page is postback (with this java-line:
document.getElementById("ins").action="thispage.aspx"), instead of
performing the code after "If Page.IsPostBack Then", it shows the original
aspx file again.

Any idea what i have to change to do what i want to do?
Thanks
Harry


aspx file:
-------
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider = ... ; Data Source =...;">
</asp:SqlDataSource>
<asp:HiddenField ID="HiddenField1" runat="server" />
</form>

<form id="ins" style="width:750px;background-color:Gray" method="post">
<input id="sql" name="sql" type="hidden" />
<input id="conn" name="conn" type="hidden" />
<input runat="server" id="Submit1" type="button" value="Klik hier om
te bewaren" onclick="sendtodb()"/>
</form>

<script language="javascript" type="text/javascript">

function sendtodb()
{
var nfieldout=document.getElementById("hiddenfield1").value
......
......
document.getElementById("sql").value=inscomm
document.getElementById("conn").value=conn
document.getElementById("ins").action="thispage.aspx"
document.getElementById("ins").submit()
return true;
</script>


code-behind
-----------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Dim conn, sql
sql = Request.Form("sql")
conn = Request.Form("conn")
Dim oConnection As OleDbConnection
Dim sConnection As String
oConnection = New OleDbConnection()
Dim comd As OleDbCommand
sConnection = conn
oConnection.ConnectionString = sConnection
oConnection.Open()
comd = New OleDbCommand(sql, oConnection)
comd.ExecuteNonQuery()
oConnection.Close()
else
HiddenField1.Value = "1"
.......
.......
end if
end sub
 
G

Guest

Harry,
From what you have written, it *sounds* like what you want to do is a
cross-page postback. Look up the term "cross-page postback" and you will find
examples and description of how to use.
Peter
 
H

Harry

Peter, thanks for replying.

Maybe my explanation was not good, but i don't think it's cross-page
postback, since the 'action' method in javascript of the form
(document.getElementByI("ins").action="thispage.aspx") refers to itself
("thispage.aspx"). The whole code here below is contained in "thispage.aspx"
and "thispage.aspx.vb".
 
B

bruce barker

IsPostBack just checks for the "__Viewstate" hidden field in the
postback form fields. as you are submitting a different form on the page
then the one containing the viewstate, the viewstate hidden field is not
included in the postback data


-- bruce (sqlwork.com)
 
H

Harry

Thanks for the explanation.
Now, if you would have a solution in mind for that, it would be great.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top