postback - How to get textbox value in ASP.NET click eventhandler -
somehow 1 of stored procedures stopped executing aspx page. works if run sql server using exec
. when click button on aspx page assigns parameters , values, , launches procedure, page reloads data not updated. button can run create or update procedure, depending on page parameters in address bar. nothing executed.
in aspx page create button this:
<asp:button id="btnsavechanges" runat="server" class="class_button normal enabled" onclick="btnsavechanges_click" text="save changes" width="100" />
then in code-behind file:
protected void btnsavechanges_click(object s, eventargs e) { //if (page.isvalid) //{ sqlcommand sqlcomm1 = new sqlcommand(); sqlconnection sqlconn1 = new sqlconnection("server=localhost\\sqlexpress;database=testdb;integrated security=true"); sqlconn1.open(); if(param_id == 0) { sqlcomm1 = new sqlcommand("dcspcreateempdetails", sqlconn1); } if(param_id > 0) { sqlcomm1 = new sqlcommand("dcspupdateempdetails", sqlconn1); } sqlcomm1.commandtype = commandtype.storedprocedure; if (param_id > 0) sqlcomm1.parameters.addwithvalue("@empid", param_id); sqlcomm1.parameters.addwithvalue("@empname1", tbname1.text); sqlcomm1.parameters.addwithvalue("@empsurname", tbsurname.text); sqlcomm1.parameters.addwithvalue("@empbirthdate", convert.todatetime(tbbirthdate.text)); sqlcomm1.executenonquery(); //} sqlconn1.close(); }
that's it. page valid, 100%. , if remove validation check, no result.
here procedure:
create procedure dcspupdateempdetails @empid int, @empname1 nvarchar(50) = null, @empsurname nvarchar(50) = null, @empbirthdate datetime = null update employees set name_1 = @empname1, surname = @empsurname, date_of_birth = @empbirthdate (employee_id = @empid)
hope you'll me it, guys. don't understand happened stuff...
updates topic:
examining debug messages found, textbox loses text before stored procedure in onclick
event takes text parameter.
is normal server first restores page , after executes code in onclick
event? think it's logically incorrect because page_load
designed load default page, while buttons , other controls used change , manipulate content of page. why need controls if code can't execute timely?
ok, problem has been resolved. how? don't know. took backup copy , copied stuff regarding problem current version. same thing, absolutely identical code. replaced current code same code backup , works now. that? i'm 100% know there no differences between them, it's quite small piece of code.
unfortunately can't mark answer because there comments here. i'll mark one.
anyway, thank you, guys. many tim attention , richard deeming suggestions.
Comments
Post a Comment