ImageButton ASP.Net 更改控件中的图像 URL
我正在 ASP 4 中设置一个 Web 用户控件。该控件本身工作正常,并且 onload 的代码甚至与我的标准 aspx 页面中使用的代码相同。
protected void GetTranslationImage(object sender, EventArgs e)
{
ImageButton image = (ImageButton)sender;
objTranslation = new TranslationsHelper();
string sTranslationID = image.ImageUrl.ToString();
string lang = ((NRMaster)this.Master).Language;
lang = lang == null ? "en-gb" : lang;
image.ImageUrl = objTranslation.GetTranslation(sTranslationID, lang);
}
当对象通过 onLoad 传递时,它在 GetTranslationImage 期间不包含默认 URL。该对象更改为所需的翻译,但它会在页面加载时恢复为 HTML 中的内容。
ImageButton 的定义如下:
<asp:ImageButton ID="btnSearch" runat="server" name="Search" value="Search" class="Search" src="/_resources/img/BTN_search.gif" onclick="btnSearch_Click" onLoad="GetTranslationImage" />
控件是否改变该函数需要运行的时间。
任何帮助将不胜感激。
谢谢 詹姆斯
I'm setting up a Web User Control in ASP 4. The control itself works correctly, and the code for the onload even is the same as used in my standard aspx pages.
protected void GetTranslationImage(object sender, EventArgs e)
{
ImageButton image = (ImageButton)sender;
objTranslation = new TranslationsHelper();
string sTranslationID = image.ImageUrl.ToString();
string lang = ((NRMaster)this.Master).Language;
lang = lang == null ? "en-gb" : lang;
image.ImageUrl = objTranslation.GetTranslation(sTranslationID, lang);
}
When the object is passed through onLoad it doesn't contain the default URL during GetTranslationImage. The object changes to the translation required however it reverts back following in the HTML on the page load.
The definition of the ImageButton is as follows:
<asp:ImageButton ID="btnSearch" runat="server" name="Search" value="Search" class="Search" src="/_resources/img/BTN_search.gif" onclick="btnSearch_Click" onLoad="GetTranslationImage" />
Does the control alter the time this function needs to be run.
Any help would be greatly appreciated.
Thank You
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 OnLoad 中覆盖它,为什么要设置
src="/_resources/img/BTN_search.gif"
?1:删除它
或
2:将其更改为:
Why are you setting
src="/_resources/img/BTN_search.gif"
if you are overwriting it in OnLoad?1: Remove it
Or
2: Change it to:
如果您从用户控件中公开转换方法,并且只需在页面加载中调用该方法,会怎么样?
用户控件 c# .net 内的公共方法
What if you made the transition method public from within the usercontrol and you simply call out to that method in your page load?
Public Methods inside User control c# .net