我们可以为动态创建的文本框提供水印吗? [英] can we give watermark for dynamically created textbox ?

查看:72
本文介绍了我们可以为动态创建的文本框提供水印吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了10个动态文本框..1是用于用户名,第2个用于密码等等。所以我想为每个文本框设置水印。所以用户应该知道哪个文本框用于用户名,哪个用于密码。 .plz帮帮我...



//创建动态文本框的代码



I have created 10 dynamic textboxes..1st is for username and 2nd is for password and so on .so i want to set watermark for each textbox..so user should know which textbox is for username and which is for password..plz help me...

//code to create dynamic textbox

int count=(int)ViewState["textboxcount"];
            count++;

            for (int i = 0; i <= count; i++)
            {
                ViewState["textboxcount"] = (int.Parse(ViewState["textboxcount"].ToString()) + 1).ToString();
                //Response.Write("Last Control ID" + ButtonName + Environment.NewLine);
                TextBox TxtATUserID = new TextBox();
                TextBox TxtATPassword = new TextBox();
                TxtATUserID.ID = "TxtUserName" + ViewState["textboxcount"].ToString();
                // TxtATUserID.Text = TxtATUserID.ID.ToString();
                TxtATPassword.ID = "TxtPassword" + ViewState["textboxcount"].ToString();
                // TxtATPassword.Text = TxtATPassword.ID.ToString();

                TxtATPassword.TextMode = TextBoxMode.Password;
                this.PlaceHolder1.Controls.Add(TxtATUserID);
                this.PlaceHolder1.Controls.Add(TxtATPassword);

推荐答案

您需要在运行时向 TextBox 添加一些属性,以便它可以 WaterMarked



参考 - Asp.net在javascript中为文本框创建水印文本 [ ^ ],这是在 TextBox上执行 WaterMarking 的最简单方法/ code>。但 TextBox 不是动态的。

You need to add some attribute to the TextBox at runtime so that it can be WaterMarked.

Refer - Asp.net create watermark text for textbox in javascript[^], which the simplest method to do the WaterMarking on TextBox. But the TextBox is not dynamic.
<asp:Textbox ID="txtUserName" 

             runat="server" 

             Text="Enter Username Here" 

             ForeColor="Gray" 

             onblur="WaterMark(this, event);" 

             onfocus="WaterMark(this, event);" />



因此,这里定义了不同的属性来执行此任务。



由于你有动态 TextBox ,所以你必须从后面的代码中动态添加它们。

使用那里定义的 javaScript 函数并添加以下代码以动态添加属性。



所以,你需要3个步骤。


So, here there are different attributes defined to do this task.

As you have dynamic TextBox, so you have to just add those dynamically from code behind.
Use the javaScript functions defined there and add the following codes to add attributes dynamically.

So, you need to 3 steps.

  1. 文本添加到 TextBoxes
  2. 添加灰色 颜色
  3. 添加属性。







TextBox TxtATUserID = new TextBox();
TextBox TxtATPassword = new TextBox();

// Add text to TextBoxes.
TxtATUserID.Text = "User ID";
TxtATPassword.Text = "Password";

// Add Gray color.
TxtATUserID.ForeColor = System.Drawing.Color.Gray;
TxtATPassword.ForeColor = System.Drawing.Color.Gray;

// Add the Attributes.
TxtATUserID.Attributes.Add("onblur", "javascript:WaterMark(this, event);");
TxtATUserID.Attributes.Add("onfocus", "javascript:WaterMark(this, event);");
TxtATPassword.Attributes.Add("onblur", "javascript:WaterMark(this, event);");
TxtATPassword.Attributes.Add("onfocus", "javascript:WaterMark(this, event);");

TxtATUserID.ID = "TxtUserName" + ViewState["textboxcount"].ToString();
TxtATPassword.ID = "TxtPassword" + ViewState["textboxcount"].ToString();

TxtATPassword.TextMode = TextBoxMode.Password;
this.PlaceHolder1.Controls.Add(TxtATUserID);
this.PlaceHolder1.Controls.Add(TxtATPassword);





注意

别忘了添加 javaScript 函数 WaterMark() 在您的页面中。



NOTE
Don''t forget to add that javaScript function WaterMark() in your page.


这篇关于我们可以为动态创建的文本框提供水印吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆