In ASp.net Page I Need To Know How To Maintain The Value Of A Particular Label Assign By the HTML Button Click. after Postback Done.
with out converting label to textbox, not using hidden field or session

Detailed Code

 <table>
        <tr>
            <td><asp:Label ID="lbl1" runat="server" ClientIDMode="Static">Before Changing</asp:Label></td>

            <td><asp:Label id="lbl2" runat="server" ClientIDMode="Static"></asp:Label></td>

            <td><asp:TextBox ID="txtbox" runat="server"></asp:TextBox></td>

</tr>

        <tr>
            <td><asp:Button ID="btnasp" runat="server"  Text="ASP Button" Height="50px" Width="150px" OnClick="btnasp_Click"/></td>

            <td><input type="button" id="btnhtml" value="HTML Button" onclick="showlabel()"  style="height:50px; width:150px"/></td>
        </tr>

    </table>

Script

 <script type="text/javascript">
    function showlabel() {
        $('#lbl1').text("After Changing");

        }
</script>

cs code

   protected void btnasp_Click(object sender, EventArgs e)
    {

        txtbox.Text = lbl1.Text;
    }

OutPut

[label"Before Changing"]                      [txtbox] 

[asp button]  [html button]

If I click HTML Button

The Label Text Before Changing Is Change To After Changing

Then I Click The ASP Button After Changing Value is show in textbox

This Is Done By With Out adding value in Hidden Field and Not Using the Server Control to Html Button,

How It Possible Plz Help Me ...

Recommended Answers

All 5 Replies

i think you can add value of label in query string . and on page load event just check if it is post back then get the value from query string and set to label :P .

i think you can add value of label in query string . and on page load event just check if it is post back then get the value from query string and set to label :P .

This would of course allow it to be changed by the user by editing the URL bar, causing security implications. Not sure if that would cause problems for the OP; Depends upon what information is being maintained between pages.

Otherwise a fine suggestion.

Hi, a simple approach would be to create a property that would get and set the value(s) and then you can easily use that property value.

@KM499 Can You Plz Add Some Sample Get Set Code For Above Code

It would be like as follows :-

private string _myProperty = string.Empty;
public string MyProperty
{
   get 
   { 
       return _myProperty; 
   }
   set
   {
       _myProperty = myLabel.Text;
   }
}

And so it would set a public property as MyProperty and you can access the label value throughout the page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.