Monday 15 April 2013

c# - ASP.NET TextChanged won't fire -



c# - ASP.NET TextChanged won't fire -

i'm doing form users send info can see. want create event when user has written text illustration description , clicks away event comes, illustration pop message saying "hello". have added textchanged function text box , autopostback set true. im new asp.net in every tutorial have checked says have add together these things able want do. have noticed registering text alter because when debug site on net explorer , write description , click away. on low left corner of ie says "error on page" when have written in description , clicked away otherwise there reads "done". firing somehow doesn't matter code set within of textchanged wont run it.

here files:

aspx.cs:

using system; using system.collections.generic; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.web.security; using system.net.mail; using system.net.mime; using system.io; using system.text; public partial class _default : system.web.ui.page { static readonly string atturl = @"c:\asdbugreport/wsasdbugreport/attachments/"; int attnumber = 0; string useremail = ""; string mysiteaddress = "http://company.com:xyz/mysearch="; string project; protected void page_load(object sender, eventargs e) { if (page.ispostback) { useremail = user.identity.name.tostring(); if (cb9.visible == true) { attnumber++; } if (cb8.visible == true) { attnumber++; } if (cb7.visible == true) { attnumber++; } if (cb6.visible == true) { attnumber++; } if (cb5.visible == true) { attnumber++; } if (cb4.visible == true) { attnumber++; } if (cb3.visible == true) { attnumber++; } if (cb2.visible == true) { attnumber++; } if (cb1.visible == true) { attnumber++; } if (cb0.visible == true) { attnumber++; } } else { clientscript.registerclientscriptblock(page.gettype(),"script","src='popup.js';", true); ddlcomponent.items.insert(0, new listitem(string.empty, string.empty)); ddlpriority.items.insert(0, new listitem(string.empty, string.empty)); ddlissuetype.items.insert(0, new listitem(string.empty, string.empty)); } } protected void btnsaveattachment_click(object sender, eventargs e) { if (attnumber == 10) { clientscript.registerclientscriptblock(page.gettype(), "script", "alert('max 10 attachments');", true); } else { if (fuissueattachmentuppload.filename.length > 0) { addattachmenttocheckbox(); saveattachment(); } else { } } } protected void saveattachment() { if(fuissueattachmentuppload.hasfile) { attnumber++; fuissueattachmentuppload.saveas(atturl.tostring() + fuissueattachmentuppload.filename.tostring()); } else{} } protected void addattachmenttocheckbox() { if (attnumber == 0) { cb0.visible = true; cb0.text = fuissueattachmentuppload.filename.tostring(); cb0.checked = true; } else if (attnumber == 1) { cb1.visible = true; cb1.text = fuissueattachmentuppload.filename.tostring(); cb1.checked = true; } else if (attnumber == 2) { cb2.visible = true; cb2.text = fuissueattachmentuppload.filename.tostring(); cb2.checked = true; } else if (attnumber == 3) { cb3.visible = true; cb3.text = fuissueattachmentuppload.filename.tostring(); cb3.checked = true; } else if (attnumber == 4) { cb4.visible = true; cb4.text = fuissueattachmentuppload.filename.tostring(); cb4.checked = true; } else if (attnumber == 5) { cb5.visible = true; cb5.text = fuissueattachmentuppload.filename.tostring(); cb5.checked = true; } else if (attnumber == 6) { cb6.visible = true; cb6.text = fuissueattachmentuppload.filename.tostring(); cb6.checked = true; } else if (attnumber == 7) { cb7.visible = true; cb7.text = fuissueattachmentuppload.filename.tostring(); cb7.checked = true; } else if (attnumber == 8) { cb8.visible = true; cb8.text = fuissueattachmentuppload.filename.tostring(); cb8.checked = true; } else if (attnumber == 9) { cb9.visible = true; cb9.text = fuissueattachmentuppload.filename.tostring(); cb9.checked = true; } } protected void btnsend_click(object sender, eventargs e) { if (componentsvalidate() == true) { sendemail(); emptyform(); clientscript.registerclientscriptblock(page.gettype(), "script", "alert('success');", true); } else {clientscript.registerclientscriptblock(page.gettype(), "script", "alert('all required fields not filled');", true); } } private boolean componentsvalidate() { rfvissuetype.validate(); rfvcomponent.validate(); rfvheader.validate(); rfvdescription.validate(); bool b = true; if (!rfvissuetype.isvalid) { b = false; } if (!rfvcomponent.isvalid) { b = false; } if (!rfvheader.isvalid) { b = false; } if (!rfvdescription.isvalid) { b = false; } homecoming b; } private void emptyform() { txtissueheader.text = ""; txtissuedescription.text = ""; cb0.text = ""; cb1.text = ""; cb2.text = ""; cb3.text = ""; cb4.text = ""; cb5.text = ""; cb6.text = ""; cb7.text = ""; cb8.text = ""; cb9.text = ""; cb0.text = ""; cb0.visible = false; cb1.visible = false; cb2.visible = false; cb3.visible = false; cb4.visible = false; cb5.visible = false; cb6.visible = false; cb7.visible = false; cb8.visible = false; cb9.visible = false; ddlcomponent.clearselection(); ddlissuetype.clearselection(); ddlpriority.clearselection(); ddlymparisto.clearselection(); txtcompany.text = ""; } private string getuseremail(string user) { int le = user.length -8; user = user.substring(8, le); user = user.tolower() + "@company.com"; homecoming user; } private string getmysite(string user) { int le = user.length - 8; user = user.substring(8, le); string s = mysiteaddress + user.tolower(); homecoming s; } public void sendemail() { if (ddlissuetype.selectedvalue == "bug") { project = "bugs"; } else if (ddlissuetype.selectedvalue == "feature request") { project = "company"; } else if (ddlissuetype.selectedvalue == "user rights") { project = "user"; } else { project = "company"; } mailaddress = new mailaddress(getuseremail(useremail).tostring()); mailaddress = new mailaddress("asd@company.com"); mailmessage asdmail = new mailmessage(from,to); asdmail.subject = txtissueheader.text.tostring(); asdmail.body = "@ext.creator = " + getuseremail(useremail).tostring() + "\n" + "@ext.creator.url = " + getmysite(useremail).tostring() + "\n" + "@environment = " + ddlymparisto.selecteditem.text.tostring() + " : " + txtcompany.text.tostring() + "\n" + "@project = " + project.tostring() + "\n" + "@issuetype = " + ddlissuetype.selecteditem.value.tostring() + "\n" + "@components = " + ddlcomponent.selecteditem.text.tostring() + "\n" + "\n" + txtissuedescription.text.tostring(); if (attnumber > 0) { if (cb9.text.length > 0) { if (cb9.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb9.text.tostring(), mediatypenames.application.octet)); } } if (cb8.text.length > 0) { if (cb8.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb8.text.tostring(), mediatypenames.application.octet)); } } if (cb7.text.length > 0) { if (cb7.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb7.text.tostring(), mediatypenames.application.octet)); } } if (cb6.text.length > 0) { if (cb6.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb6.text.tostring(), mediatypenames.application.octet)); } } if (cb5.text.length > 0) { if (cb5.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb5.text.tostring(), mediatypenames.application.octet)); } } if (cb4.text.length > 0) { if (cb4.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb4.text.tostring(), mediatypenames.application.octet)); } } if (cb3.text.length > 0) { if (cb3.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb3.text.tostring(), mediatypenames.application.octet)); } } if (cb2.text.length > 0) { if (cb2.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb2.text.tostring(), mediatypenames.application.octet)); } } if (cb1.text.length > 0) { if (cb1.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb1.text.tostring(), mediatypenames.application.octet)); } } if (cb0.text.length > 0) { if (cb0.checked) { asdmail.attachments.add(new attachment(atturl.tostring() + cb0.text.tostring(), mediatypenames.application.octet)); } } } smtpclient client = new smtpclient(); client.send(asdmail); if (deleteattachments()) { } } private boolean deleteattachments() { bool r = true; if (attnumber == 1) { seek { fileinfo thefile = new fileinfo(mappath(cb0.text.tostring())); if (thefile.exists) { seek {file.delete(cb0.text.tostring());} grab { } } else { r = false; throw new filenotfoundexception(); } } grab (filenotfoundexception ex) { } grab (exception ex) { } } else if (attnumber == 2) { seek { fileinfo thefile = new fileinfo(cb1.text.tostring()); if (thefile.exists) { seek { file.delete(cb1.text.tostring()); } grab { } } else { r = false; throw new filenotfoundexception(); } } grab (filenotfoundexception ex) { } grab (exception ex) { } } else if (attnumber == 3) { seek { fileinfo thefile = new fileinfo(cb2.text.tostring()); if (thefile.exists) { seek { file.delete(cb2.text.tostring()); } grab { } } else { r = false; throw new filenotfoundexception(); } } grab (filenotfoundexception ex) { } grab (exception ex) { } } else if (attnumber == 4) { seek { fileinfo thefile = new fileinfo(cb3.text.tostring()); if (thefile.exists) { seek { file.delete(cb3.text.tostring()); } grab { } } else { r = false; throw new filenotfoundexception(); } } grab (filenotfoundexception ex) { } grab (exception ex) { } } homecoming r; } private void hidecheckbox() { if (attnumber == 0) { cb0.visible = false; } if (attnumber == 1) { cb1.visible = false; } if (attnumber == 2) { cb2.visible = false; } if (attnumber == 3) { cb3.visible = false; } if (attnumber == 4) { cb4.visible = false; } if (attnumber == 5) { cb5.visible = false; } if (attnumber == 6) { cb6.visible = false; } if (attnumber == 7) { cb7.visible = false; } if (attnumber == 8) { cb8.visible = false; } } protected void cb0_checkedchanged(object sender, eventargs e) { if (!cb0.checked) { attnumber = attnumber - 1; cb0.visible = false; cb0.text = cb1.text.tostring(); cb1.text = cb2.text.tostring(); cb2.text = cb3.text.tostring(); cb3.text = cb4.text.tostring(); cb4.text = cb5.text.tostring(); cb5.text = cb6.text.tostring(); cb6.text = cb7.text.tostring(); cb7.text = cb8.text.tostring(); cb8.text = cb9.text.tostring(); if (attnumber >= 1) { cb0.visible = true; cb0.checked = true; } hidecheckbox(); } } protected void cb1_checkedchanged(object sender, eventargs e) { if (!cb1.checked) { attnumber = attnumber - 1; cb1.visible = false; cb1.text = cb2.text.tostring(); cb2.text = cb3.text.tostring(); cb3.text = cb4.text.tostring(); cb4.text = cb5.text.tostring(); cb5.text = cb6.text.tostring(); cb6.text = cb7.text.tostring(); cb7.text = cb8.text.tostring(); cb8.text = cb9.text.tostring(); if (attnumber >= 2) { cb1.visible = true; cb1.checked = true; } hidecheckbox(); } } protected void cb2_checkedchanged(object sender, eventargs e) { if (!cb2.checked) { attnumber = attnumber - 1; cb2.visible = false; cb2.text = cb3.text.tostring(); cb3.text = cb4.text.tostring(); cb4.text = cb5.text.tostring(); cb5.text = cb6.text.tostring(); cb6.text = cb7.text.tostring(); cb7.text = cb8.text.tostring(); cb8.text = cb9.text.tostring(); if (attnumber >= 3) { cb2.visible = true; cb2.checked = true; } hidecheckbox(); } } }

aspx:

<%@ page title="home page" language="c#" masterpagefile="~/site.master" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" theme="skinstyleofasdform" %> <asp:content id="headercontent" runat="server" contentplaceholderid="headcontent"> </asp:content> <asp:content id="bodycontent" runat="server" contentplaceholderid="maincontent"> <div id="divheader"> <asp:label id="lblheader" runat="server" text="it stuff" font-bold="true" font-size="large"></asp:label> </div><br /> <div id="divcontent"> <div id="divissueheader"> <asp:label id="lblissueheader" runat="server" text="header:"></asp:label><br /> <asp:textbox id="txtissueheader" runat="server" width="394px" causesvalidation="true" tooltip="write header"></asp:textbox> <asp:requiredfieldvalidator id="rfvheader" runat="server" controltovalidate="txtissueheader" errormessage="fill missing info" forecolor="red"></asp:requiredfieldvalidator> </div><br /> <div id="divissuetype" style="height: 70px;"> <asp:label id="lbissuetype" runat="server" text="type: "></asp:label><br /> <asp:dropdownlist id="ddlissuetype" runat="server" datavaluefield="id" skinid="ddlistskinid" appenddatabounditems="true" causesvalidation="true" tooltip="give type"> <asp:listitem value="bug">bug</asp:listitem> <asp:listitem value="feature request">feature</asp:listitem> <asp:listitem value="user rights">user</asp:listitem> </asp:dropdownlist> <asp:requiredfieldvalidator id="rfvissuetype" runat="server" controltovalidate="ddlissuetype" errormessage="fill missing info" forecolor="red"></asp:requiredfieldvalidator> </div> <div id="divissuecomponent" style="height: 70px;"> <asp:label id="lbissuecomponent" runat="server" text="system: "></asp:label><br /> <asp:dropdownlist id="ddlcomponent" runat="server" datasourceid="dscomponents" datatextfield="cname" datavaluefield="componentid" skinid="ddlistskinid" appenddatabounditems="true" causesvalidation="true" tooltip="choose system"> </asp:dropdownlist> <asp:requiredfieldvalidator id="rfvcomponent" runat="server" controltovalidate="ddlcomponent" errormessage="fill missing info" forecolor="red"></asp:requiredfieldvalidator> <asp:sqldatasource id="dscomponents" runat="server" connectionstring="<%$ connectionstrings:asddbconnectionstring %>" selectcommand="select id componentid, cname, project asdschema.component (project = '9999')"> </asp:sqldatasource> </div> <div id="divissueassignee" style="height: 70px;"> <asp:label id="lblenvi" runat="server" text="envi:"></asp:label> <br /> <asp:dropdownlist id="ddlymparisto" runat="server" appenddatabounditems="true" tooltip="choose envi"> <asp:listitem selected="true">basic</asp:listitem> <asp:listitem>test</asp:listitem> </asp:dropdownlist> <br /> <asp:label id="lblcompany" runat="server" text="envi "></asp:label> <br /> <asp:textbox id="txtcompany" runat="server"></asp:textbox> </div> <br /> <div id="divissuedescription"> <asp:label id="lblissuedescription" runat="server" text="desc "></asp:label> <asp:requiredfieldvalidator id="rfvdescription" runat="server" controltovalidate="txtissuedescription" errormessage="fill missing info" forecolor="red"></asp:requiredfieldvalidator> <br /> <asp:textbox id="txtissuedescription" runat="server" height="345px" textmode="multiline" width="586px" causesvalidation="true" enabletheming="true" style="margin-right: 0px"></asp:textbox> </div><br /> <div id="divissueattachment"> <asp:label id="lblissueattachment" runat="server" text="attach file "></asp:label><br /> <asp:fileupload id="fuissueattachmentuppload" runat="server" width="218px" enableviewstate="false" viewstatemode="disabled" /><br /> <asp:button id="btnsaveattachment" runat="server" text="attach" onclick="btnsaveattachment_click" width="69px" causesvalidation="false" /><br /> <asp:checkbox id = "cb0" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb0_checkedchanged"></asp:checkbox><br /> <asp:checkbox id = "cb1" runat="server" visible= "false" viewstatemode="enabled" autopostback="true" oncheckedchanged="cb1_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb2" runat="server" visible="false" autopostback="true" oncheckedchanged="cb2_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb3" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb3_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb4" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb4_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb5" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb5_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb6" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb6_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb7" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb7_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb8" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb8_checkedchanged"> </asp:checkbox><br /> <asp:checkbox id = "cb9" runat="server" visible= "false" autopostback="true" oncheckedchanged="cb9_checkedchanged"> </asp:checkbox><br /> </div> <div id="divsend"> <asp:button id="btnsend" runat="server" text="send" onclick="btnsend_click" height="28px" width="290px" causesvalidation="false"/> </div> </div> </asp:content>

don't utilize auto postback when info changed in fields.

postback - should in dictionary pain, ugly, , harmful user experience. when abused.

update panel - avoid lovely screen flicker you'll end implementing update panel create big chunk of page pain work on. consume excessive memory, take page @ instance , commit memory. refresh new changes, keeping both in memory.

i'm assuming attempting validate users input. utilize several libraries such valid8, or write simple validation in javascript yourself. approach alleviate postback client have validation present.

example:

$(document).ready(function () { if($("#<%= txtfirstname.clientid %>").val() == '') { $(this).css({ border: "red" }); } });

simple, if field null create border red. provide functionality without postback ensure utilize onclientclick , create function. though big chunk of done client should check info on server. ensure hasn't been tampered.

hope explains why should avoid excessive postback approach, implement.

c# asp.net

No comments:

Post a Comment