C
C#•3d ago
AideedSS

C# ASP.NET, Why do I have to press button twice to make it works

I make a button, and I put PageLoad
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["project_name"] = "Asuka No Sora";
ViewState["pick_page"] = "0";
ViewState["pick_filepath"] = "";
}
populatePage();

}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["project_name"] = "Asuka No Sora";
ViewState["pick_page"] = "0";
ViewState["pick_filepath"] = "";
}
populatePage();

}
This is the imagebutton that requires me to click twice. If I click only once, it does not run populatePage()
ImageButton img = new ImageButton();
img.Width = 200;
img.Height = 200;
img.ImageUrl = $"{imagePath}";
if(ViewState["pick_page"].ToString().Equals(pageNumber.ToString()))
{
img.CssClass = "PageItem border-3 border-emerald-500 hover:border-emerald-300";
}
else
{
img.CssClass = "PageItem border-3 border-gray-500 hover:border-white";
}
img.Click += (a, b) =>
{
SelectPage(pageNumber, filePath, imagePath);
};
ImageButton img = new ImageButton();
img.Width = 200;
img.Height = 200;
img.ImageUrl = $"{imagePath}";
if(ViewState["pick_page"].ToString().Equals(pageNumber.ToString()))
{
img.CssClass = "PageItem border-3 border-emerald-500 hover:border-emerald-300";
}
else
{
img.CssClass = "PageItem border-3 border-gray-500 hover:border-white";
}
img.Click += (a, b) =>
{
SelectPage(pageNumber, filePath, imagePath);
};
5 Replies
𓀠𓀒𓀡𓀬
prob img.Click i assume mybe that function requires you to click twice nvm its a field. what is Click in ImageButton class Console.WriteLine("Image clicked"); nvm
AideedSS
AideedSSOP•3d ago
probably, hurmmm, any idea how to assign its click event in much proper way? I mean, the ImageButton was generated by c# tho wait, how do you see console log in ASP.NET WebForm?
𓀠𓀒𓀡𓀬
That doesnt exist in c#
jcotton42
jcotton42•3d ago
Web Forms runs on the server.
AideedSS
AideedSSOP•2d ago
hurmm, I meant, the name of framework is ASP.NET..the old one

Did you find this page helpful?