how to change text of label in asp.net dotnetnuke c# and display it on page? -
i want put error messages on page @ runtime using labels.
so have done following type of code.
protected void insertbutton_click(object sender, eventargs e) { //this.formview1.visible = false; //linkbutton1.text = "update successful - add page"; textbox txtauthor = this.formview1.findcontrol("txtpageauthor") textbox; textbox txttitle = this.formview1.findcontrol("txtpagetitle") textbox; textbox txttag = this.formview1.findcontrol("txttagname") textbox; label lblauthor = this.formview1.findcontrol("lblauthor") label; label lbltitle = this.formview1.findcontrol("lbltitle") label; label lbltag = this.formview1.findcontrol("lbltag") label; if (string.isnullorempty(txtauthor.text)) { lblauthor.text = "author name must entered"; valid = 1; } if (string.isnullorempty(txttitle.text)) { lbltitle.text = "page title must entered"; valid = 1; } if (string.isnullorempty(txttag.text)) { lbltag.text = "tag name must entered"; valid = 1; } page_load(sender, e); this.gridview1.databind(); } // page load event public void page_load(object sender, eventargs e) { label lblauthor = this.formview1.findcontrol("lblauthor") label; label lbltitle = this.formview1.findcontrol("lbltitle") label; label lbltag = this.formview1.findcontrol("lbltag") label; if (page.ispostback) { //if (valid != 0) //{ lblauthor.text = "author name must entered"; lbltitle.text = "page title must entered"; lbltag.text = "tag name must entered"; //} } }
below have mentioned insertbutton's aspx code:
<div class="lineheight"> <p style="display: inline; float: left; width: 100%"> <asp:label id="lblblank" runat="server" text=" " width="100px" style="float: left;"></asp:label> <asp:linkbutton id="insertbutton" runat="server" causesvalidation="true" commandname="insert" text="add page" cssclass="btn" onclick="insertbutton_click" /> <asp:linkbutton id="insertcancelbutton" runat="server" causesvalidation="false" commandname="cancel" text="cancel" cssclass="btn" onclick="insertcancelbutton_click" /> </p> </div>
but everytime click add button whole page redirected , default value of label i.e. "" (blank) printed on page.
all answers warmly welcome..
thanks in advance..
you can use asp validators. , more simpler, , can make custom validators. here link
Comments
Post a Comment