asp.net传递字符串变量到用户控件 [英] asp.net passing string variable to a user control

查看:156
本文介绍了asp.net传递字符串变量到用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想后面的变量code的值传递给像一个用户控件:

I am trying to pass value of a code behind variable to a user control like:

<pv1:ShowPdf ID="ShowPdf2" runat="server" BorderStyle="Inset" BorderWidth="2px" FilePath='<%=path2%>'
        Height="700px" Width="856px" />

其中,路径2是code声明背后一个受保护的字符串变量。
问题在于PATH2的值不被传递到文件路径。什么是我作出了错误?
简单地做与LT;%=路径2%>给我的页面上的路径2变量的正确值。
任何帮助将是最AP preciated。

where path2 is a protected string variable declared in code behind. The problem is that the value of path2 is not being passed to the FilePath. What is the mistake I am making? Simply doing <%=path2%> gives me correct value of the path2 variable on the page. Any help will be most appreciated.

-
阿里

-- Ali

推荐答案

使用&LT;%= 是一样的使用的Response.Write(字符串)。这发生在生命周期的,当你ShowPdf控制正在建造和属性初始化比不同点 - 晚得多。尝试,而不是使用&LT;%#,其中规定的DataBind过程中的价值。您可能需要的CreateChildControls或者路径2 被赋予一种价值其他一些方法来调用DataBind你的页面。

Using <%= is the same as using Response.Write(string). This happens at a different point in the lifecycle than when your ShowPdf control is being built and properties being initialized - much later. Try instead using <%#, which sets the value during DataBind. You may need to call DataBind on your Page in CreateChildControls or some other method where path2 is being given a value.

这篇关于asp.net传递字符串变量到用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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