开发者

Problem with sql statement and PostBackUrl

开发者 https://www.devze.com 2023-03-12 17:02 出处:网络
I have an sql statement that I posted on this site, and I applied in my website that works and inserts users name and information into the database soon after the user presses the submit button.

I have an sql statement that I posted on this site, and I applied in my website that works and inserts users name and information into the database soon after the user presses the submit button.

This however doesnt happen when I set the the submit's buttons PostBackUrl property. When I do this, no data is inserted, and the whole 开发者_开发技巧function that holds the execution of the insert statement seems to be skipped (as I tried to make a mistake on purpose,,and no exception was thrown).

How can i make the the postBackUrl work, so that data will have the time to be inserted?

working sqlStatment:

 insertCommand.Append("DECLARE @TopicsId int; INSERT INTO Topics(Theme,Topics,Date)");
    insertCommand.Append("VALUES(@topic,@subTopic,GETDATE())");
    insertCommand.Append("SET @TopicsId = SCOPE_IDENTITY()");

    insertCommand.Append(" INSERT INTO Threads(UsersID,TopicsID,Date,ThreadTitle,ThreadParagraph,ThreadClosed,Views,Replies,PageNumber)");
    insertCommand.Append(" SELECT @uniqueIdentifier,@TopicsID,GETDATE(),@questionTitle,@questionParagraph,0,0,0,FLOOR(Count(t.TopicsID)/20)");
    insertCommand.Append(" FROM Threads AS d INNER JOIN Topics AS t ON d.TopicsID=t.TopicsID");

working when:

<asp:Button ID="sendButton1" runat="server" Text="שלח" Width="60px" 
            onclick="sendButton1_Click"  />

non working sqlStatement when:

<asp:Button ID="sendButton1" runat="server" Text="שלח" Width="60px" 
            onclick="sendButton1_Click" PostBackUrl="~/AnswerQuestion.aspx" />


This will cause cross-page postback. It will post the current page to the provided URL in the button's PostbackURL property when the Button control is clicked. Your button Click event will not be triggered in this case.

For Details please check from MSDN

EditL Why not attempt this simply, like...

protected void Button1_Click(object sender, EventArgs e)
{
///.....Your Code.....
insertCommand.Append("DECLARE @TopicsId int; INSERT INTO Topics(Theme,Topics,Date)");
insertCommand.Append("VALUES(@topic,@subTopic,GETDATE())");
insertCommand.Append("SET @TopicsId = SCOPE_IDENTITY()");

insertCommand.Append(" INSERT INTO Threads(UsersID,TopicsID,Date,ThreadTitle,ThreadParagraph,ThreadClosed,Views,Replies,PageNumber)");
insertCommand.Append(" SELECT @uniqueIdentifier,@TopicsID,GETDATE(),@questionTitle,@questionParagraph,0,0,0,FLOOR(Count(t.TopicsID)/20)");
insertCommand.Append(" FROM Threads AS d INNER JOIN Topics AS t ON d.TopicsID=t.TopicsID");

 ///..At the end add this......
 Response.Redirect("~/AnswerQuestion.aspx");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号