Reputation: 23
I have a problem when executing below line of code, I want to show success message and then closing the current window and open another one.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
"alertMessage", "alert(' Progress Has Been Finished '),
window.close(), window.open('ReqProgDetail.aspx?v=0&codLic="+
Convert.ToInt32(_idlicense) + "#section1') ", true);
My HiddenField :
HiddenField _idlicense = (HiddenField)dv.FindControl("hid_id_license");
and this is my exception message :
System.InvalidCastException: Unable to cast object of type
'System.Web.UI.WebControls.HiddenField' to type
'System.IConvertible'.
at System.Convert.ToInt32(Object value)
Upvotes: 2
Views: 57
Reputation: 1301
You're getting an error because you're trying to convert HiddenField
object into int, so you have to retrieve value in HiddenField
object first before converting it to int
.
try changing part of your code:
Convert.ToInt32(_idlicense)
into :
Convert.ToInt32(_idlicense.Value)
Upvotes: 1