Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从代码隐藏向javascript传递控件id_Javascript_Asp.net - Fatal编程技术网

从代码隐藏向javascript传递控件id

从代码隐藏向javascript传递控件id,javascript,asp.net,Javascript,Asp.net,我正在制作一个动态图像gallary,其中文件夹的图像列在div中。 我想通过javascript增加onclick的大小 我从代码隐藏中分配onclick事件,如下所示 int count = ds.Tables[0].Rows.Count; ; for (int i = 0; i < count; i++) { ImageButton img = new ImageButton();

我正在制作一个动态图像gallary,其中文件夹的图像列在div中。
我想通过javascript增加onclick的大小

我从代码隐藏中分配onclick事件,如下所示

   int count = ds.Tables[0].Rows.Count; ;
             for (int i = 0; i < count; i++)
            {
                ImageButton img = new ImageButton();
                img.ID = "projectimg" + i.ToString();
                img.ImageUrl = ds.Tables[0].Rows[i][0].ToString();
                img.Height = 120;
                img.Width = 120;
                img.ToolTip = ds.Tables[0].Rows[0][1].ToString();
                img.OnClientClick = "incsize('" + "contentPlace_" + img.ID + "')";
              }
但这是行不通的。此代码有什么问题?

测试此代码:

img.OnClientClick = "incsize('" + "contentPlace_" + img.ID + "')";
您忘记了单个定量标记,请进行以下测试:

img.OnClientClick = "incsize('" + "contentPlace_" + img.ID + "')";
你忘记了一个定量标记

试试这个

假设您的aspx中有这样一个图像

<asp:Image ID="MyImage" runat="server" ImageUrl="~/some-image.png"/>
string script = String.Format("javascript:return incsize('{0}');", MyImage.ClientID);
MyImage.Attributes.Add("onclick", script);
function incsize(imgid) {
    //alert("jjj");
    //do some thing here as
    var img = document.getElementById(imgid);
}
现在用JavaScript这样调用它

<asp:Image ID="MyImage" runat="server" ImageUrl="~/some-image.png"/>
string script = String.Format("javascript:return incsize('{0}');", MyImage.ClientID);
MyImage.Attributes.Add("onclick", script);
function incsize(imgid) {
    //alert("jjj");
    //do some thing here as
    var img = document.getElementById(imgid);
}


请在今后的问题中明确提出您的要求。

在你的循环中这样做

ImageButton img = new ImageButton(); //Image img = new Image(); 
img.ID = "projectimg" + i.ToString(); 
img.ImageUrl = ds.Tables[0].Rows[i][0].ToString(); 
img.Height = 120; 
img.Width = 120; 
img.ToolTip = ds.Tables[0].Rows[0][1].ToString();
img.ClientIDMode = System.Web.UI.ClientIDMode.Static;
string script = String.Format("javascript:return incsize('{0}');", img.ID);
img.Attributes.Add("onclick", script);
试试这个

假设您的aspx中有这样一个图像

<asp:Image ID="MyImage" runat="server" ImageUrl="~/some-image.png"/>
string script = String.Format("javascript:return incsize('{0}');", MyImage.ClientID);
MyImage.Attributes.Add("onclick", script);
function incsize(imgid) {
    //alert("jjj");
    //do some thing here as
    var img = document.getElementById(imgid);
}
现在用JavaScript这样调用它

<asp:Image ID="MyImage" runat="server" ImageUrl="~/some-image.png"/>
string script = String.Format("javascript:return incsize('{0}');", MyImage.ClientID);
MyImage.Attributes.Add("onclick", script);
function incsize(imgid) {
    //alert("jjj");
    //do some thing here as
    var img = document.getElementById(imgid);
}


请在今后的问题中明确提出您的要求。

在你的循环中这样做

ImageButton img = new ImageButton(); //Image img = new Image(); 
img.ID = "projectimg" + i.ToString(); 
img.ImageUrl = ds.Tables[0].Rows[i][0].ToString(); 
img.Height = 120; 
img.Width = 120; 
img.ToolTip = ds.Tables[0].Rows[0][1].ToString();
img.ClientIDMode = System.Web.UI.ClientIDMode.Static;
string script = String.Format("javascript:return incsize('{0}');", img.ID);
img.Attributes.Add("onclick", script);

为什么称之为javascript?:)您是否试图将asp.net webforms代码中的某些id传递给javascript函数?为什么称为javascript?:)您是否试图将asp.net webforms代码中的某些id传递给javascript函数?这是我从中得到的html代码。这是我从这里得到的html代码。ImageButton img=newImageButton()//图像img=新图像();img.ID=“projectmg”+i.ToString();img.ImageUrl=ds.Tables[0]。行[i][0]。ToString();img.高度=120;img.宽度=120;img.ToolTip=ds.Tables[0]。行[0][1]。ToString();这是我的imagebutton,这是一个创建多个imagebutton的循环。为什么您不能在开始之前详细说明所有这些内容呢。我的代码体非常大,如果你想我可以编辑它,它会占用很多页面空间!我正在从DB和图像的geeting链接建立连接,希望在页面中添加运行时控件,并拥有一个与之关联的javascript函数,在该函数中我传递imageID并放大图像。好的,但如何在javascript中增加图像的大小我尝试了var img=document.getElementById(imgid);img.style.height='300px';img.style.width='300px';但我确实增加了大小,但图像在1秒后隐藏!!!!你应该问另一个问题。ImageButton img=newImageButton()//图像img=新图像();img.ID=“projectmg”+i.ToString();img.ImageUrl=ds.Tables[0]。行[i][0]。ToString();img.高度=120;img.宽度=120;img.ToolTip=ds.Tables[0]。行[0][1]。ToString();这是我的imagebutton,这是一个创建多个imagebutton的循环。为什么您不能在开始之前详细说明所有这些内容呢。我的代码体非常大,如果你想我可以编辑它,它会占用很多页面空间!我正在从DB和图像的geeting链接建立连接,希望在页面中添加运行时控件,并拥有一个与之关联的javascript函数,在该函数中我传递imageID并放大图像。好的,但如何在javascript中增加图像的大小我尝试了var img=document.getElementById(imgid);img.style.height='300px';img.style.width='300px';但我确实增加了大小,但图像在1秒后隐藏!!!!你应该问另一个问题。